Hi, I need help to sort a file. I am able to open the file, but the lines of the text file are separate by commas and I have to separate the lines into 4 differents string of characters. I have problems separating the string and sorting them by name. Here is waht i have so far,

#include <stdio.h>
#include <stdlib.h>

int main(void)
    char fname[30];
    char line[55];
    char line1[55];
    char line2[55];
    char line3[55];
    char line4[55];
    char title[35];
    char date [10];
    char rating [10];
    int lenght;

    FILE *movies;

    printf("Enter the name of the file: ");

    if ((movies = fopen( fname, "r")) == NULL)
        printf("File could not be opened.\n");

        printf("You got it\n");

              // fscanf(movies,"%[^\n]s",line);
               for(int i=0;i<=10;i++)

              // printf("%s\n",line3);
              // printf("%s\n",line4);

              // fscanf(movies,"%[^,]s",lenght);

             // printf("%s\n",date);


     return 0;


Please help me!!!!!

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Pedro, welcome to the forum.
If I understand you correctly what you need is to parse the lines into individual tokens.
Take a look at this tutorial.
Next time make sure you encase your code in CODE tags.
That will ensure proper format of the code and easiness of read.

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.