What is wrong with this code??? Can U help??

This is a discussion on What is wrong with this code??? Can U help?? within the C Programming forums, part of the General Programming Boards category; Hi..I got stuck with file handling.. how can I get the each line's string from the file..?? I mean..for example, ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    4

    Talking What is wrong with this code??? Can U help??

    Hi..I got stuck with file handling..
    how can I get the each line's string from the file..??
    I mean..for example, if I have file which contain

    2--->how many countries participate
    canada
    united states
    2,1-->these are score for the game

    then, how can I store each line into array??
    like ["2","canada","united states", "2,1"]

    the file format always like that, but I should handle 2 team to 256 teams..so..anyway..anybody knows how to handle the file like this??

    Here is my code....
    Code:
    #include<stdio.h>
    int main(int argc, char *argv[]){
               char *file[512];
               int line = 0;
    
               if (argc == 2){
                         FILE *fp;
                         fp = fopen(argv[1], "r");
                         while (fgets(file[line], 81, fp) != 0){
                                      printf("file[%d] is [%s] \n", line, file[line]);
                                      line++;
                         }
                          fclose(fp);
                          return (0);
               }else {
                    printf("theres no input file\n");
                          return (-1);
               }
    }

    &#91;code]&#91;/code]tagged by Salem

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Click me =>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 08:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 01:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21