I need urgent help please :(

I'm asked to write a program of a game that consists in identifying the right sequence of a random number previously defined by the computer ...
I tried this code but it doesn't work :/ I can't find out what is the problem ( I'm a beginner ):



#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <iostream>

#include <conio.h>
main()
{
char T1[8],T2[8];
int i,j,k,f,l;
char ch[8];

for(i=0;i<8;i++)
{T1[i]=rand()%10;
}

printf("the secret number is\n");

for(j=0;j<8;j++)
T2[j]='*';

for(k=0;k<8;k++)
printf("%c",T2[k]);
printf("\n");


printf("enter your first trial:\n");
scanf("%s",ch);


for(f=0;f<8;f++)
{ if(ch[f]==T1[f])
{T2[f]=ch[f];}
else {T2[f]='-';}
}

for(l=0;l<8;l++)
{printf("%c",T2[l]);}

}
Your loop goes out of bounds that's why it doesn't work well. I think you can detect those kind of problems quickly as they can arm you later. Espicially when talking about c++. I recommend use any software as help. I tend to use checkmarx which works pretty good.
Good luck!
Ben.
Topic archived. No new replies allowed.