I've a little problem with my code, why when I use printf on string1 (last line), it doesn't give me what I wrote for this variable ?
For example if I wrote : asdfgh, string1 give me something weird like : @>>..
Any idea ?
Thanks for help.
int main()
{
int length;
int i = 0;
char string1[100];
printf("Please enter the length of the two strings\n");
scanf("%d", &length);
printf("\nPlease enter the first string\n");
while((string1[i] = getchar())!='\n')
i++ ;
getchar();
printf("\nString 1 : %c", string1);
return 0;
}
%sinprintf("\nString 1 : %s", string1);also don't forget to put null-terminattor.%stoprintf()strings, not%c.whileloop reads the remainder of the first line, where the user typed in the length and pressed enter. Anything the user types after the second prompt appears will not be read.