#include<stdio.h>
main()

    FILE *pToFile;
    int input[512],i,j,k,l;
    pToFile=fopen("data.txt","r");
    if (pToFile !=NULL)
    {
        fscanf(pToFile,"%d%d %d %d %d",input,&i,&j,&k,&l);
        printf("%d\n%d\n%d\n %d\n %d\n %d\n", input,i,j,k,l);
        fclose(pToFile);
    }
    else
    {
        printf("could not open the file \n");
    }
    return(0);
}

i was wondering why this code doesn't want to work?
and if theres any another way i can read the columns in c program?

Your 'input' variable is an array of 512 possible values. Try this for your fscanf function:
fscanf(pToFile,"%d %d %d %d %d",&input[0], &i, &j, &k, &l);
Remember, the number of format items in the format string must be the same as the number of variables that you are passing to take the data. Also, your printf statement should be adusted accordingly, passing 'input[0]' instead of 'input' for the first output argument.

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.