I got a error. “Passing argument 1 ‘strchr’ makes pointer from integer without a cast”
How can I fix that ?
this happen in const char *ptr = strchr(c, ';'); and I’m trying to do is just get the index of a specific char in a char array.
In my File, I have for example 100 lines, and in each line, i has something like that 12345;Lucas, so I need to split this, numbers and letters and I’m trying to search the ” ; ” and separate.
Follow my code
FILE *fp;
char c;
char c2[100];
int i = 0;
fp = fopen("MyFile.csv", "r");
if (!fp) {
printf("Error!\n");
exit(0);
}
while((c = getc(fp)) != EOF){
for (i = 0; i < 1; i++)
{
const char *ptr = strchr(c, ';');
if(ptr) {
int index = ptr - c;
printf("%d", index);
}
}
printf("%c", c);
}
Your variable
cis a single character, not a char array.