Im working on an assignment and have run into a proglem that I cant seem to fix. With the following code I get the following error.

"warning: passing argument 2 of strchr makes integer from pointer without a cast"

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


int main()
{


char buf[250];
char *chptr;
char *strptr;
FILE *fp;


fp = fopen("FILE1", "r");
fgets(buf, 250, fp);
while(!feof(fp)) {
   chptr = strchr(buf, "\n");
   *chptr = '\0';
   strptr = strstr(buf, "=");
   if(strptr != NULL) printf("%s\n",strptr+4);
      else printf("%s\n",buf);
   fgets(buf, 250, fp);
}


}

program is supposed to read in a file and take out segments of the file. In this case im taking out "=".

It's line 18

chptr = strchr(buf, "\n");

"\n" is a string, hence a pointer, rather that an integer. if you change it to

chptr = strchr(buf, '\n');

that should fix it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.