I am trying to write C code to accept characters from a user one by one and then store them into a character array. If the user enters "1" I want the loop to terminate. The problem is that when I run the program, it just terminates and I get an error saying:
incompatible integer to pointer conversion passing 'char'
to parameter of type 'const char *'; take the address with &
[-Wint-conversion]
while (strcmp(ch, "1") != 0)
How do I correct this? BTW, I'm using the WinGW-w64 compiler for Windows 10.
I have this code thus far:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 100
int main(void)
{
int i = 0;
char ch, string[MAX];
while (strcmp(ch, "1") != 0)
{
printf("Enter a character: ");
scanf("%c", &ch);
fflush(stdin);
string[i] = ch;
i++;
}
printf("%c", string[0]);
}
while (strcmp(ch, "1") != 0)->while (ch != '1')strcmpis a function which compares 2 strings. The function expects to receive twoconst char *, but one of your arguments is achar.