I am just starting to learn C coding ,I am trying to write a program that keeps scanning names and once it scans a specific name lets say for example "John" it stops Please correct me
#include <stdio.h>
int main()
{
char name[20];
printf("enter a name:");
for(;;)
{
scanf("%s",name);
if (name='John')
{
break;
}
}
You can't compare two string pointers with !=
or ==
.
you need to use strcmp, for example:
while (strcmp(check,input) != 0)
strcmp compares the string pointed to, by str1 to the string pointed to by str2.