Dear all,
I have to interface some C code in C++, but I had a problem with sscanf
function, it has been some time I have not used C and I could not figure
out my problem. Simple code is below, I am trying to read a file with
line line 8 characters wide,
88888888
it has unix line ending LF, but I am getting a segfault from the sscanf
line. Maybe I am misusing some of the standard C functions, can you help
me locate this?
Best,
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fp;
char buffer[9];
char *Title;
char *dummy;
int ret;
fp = fopen("deneme", "r");
dummy = fgets(buffer,9, fp);
puts(dummy);
printf("line %s\n",buffer);
printf("len %d\n",(int)strl en(buffer));
ret = sscanf(buffer, "%8c%[^\n]", Title,dummy);
printf("read %d\n",ret);
return 0;
}
I have to interface some C code in C++, but I had a problem with sscanf
function, it has been some time I have not used C and I could not figure
out my problem. Simple code is below, I am trying to read a file with
line line 8 characters wide,
88888888
it has unix line ending LF, but I am getting a segfault from the sscanf
line. Maybe I am misusing some of the standard C functions, can you help
me locate this?
Best,
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fp;
char buffer[9];
char *Title;
char *dummy;
int ret;
fp = fopen("deneme", "r");
dummy = fgets(buffer,9, fp);
puts(dummy);
printf("line %s\n",buffer);
printf("len %d\n",(int)strl en(buffer));
ret = sscanf(buffer, "%8c%[^\n]", Title,dummy);
printf("read %d\n",ret);
return 0;
}
Comment