Answers for "fscanf array of string"

0

fscanf array of string

//This will reserve 100 character arrays, or 100 strings
char *arr[100];

int count = 0;
while (fscanf(fp, "%999s", str) == 1)
{
    arr[count] = malloc(strlen(str) + 1);
    strcpy(arr[count], str);
    count++;
    if (count == 100)
        break;
}

int i;
for (i = 0; i < count; i++) 
    printf("%s\n", arr[i]);
Posted by: Guest on May-04-2021

Code answers related to "fscanf array of string"

Browse Popular Code Answers by Language