C need help on array of string

Discussion in 'General Computer Support' started by jeif_lee, Dec 4, 2009.

  1. jeif_lee

    jeif_lee

    Joined:
    Dec 4, 2009
    Messages:
    1
    Hi all,
    I'm still new to writing C programs but I have to do a piece of work on file I/O,
    eg, making a phone directory.

    I got an error msg:
    "passing arg 1 of `strcpy' makes pointer from integer without a cast".

    My intention of this program is to read in text of a file from line to line,
    storing each line into an element of the array.
    i.e, wholefile[0] stores the 1st line (a string)
    wholefile[1] stores the 2nd line.

    The following is my code:

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

    int readwhole(char*, char*);

    int readwhole(char*wholefile,char*file){
    int i,j;
    char temp[30];
    i=-1;
    j=0;

    FILE *fp;
    fp=fopen(file,"r");


    do{
    i++;
    temp=fgetc(fp);
    if (temp=='\n'){
    temp='\0';
    strcpy(wholefile[j],temp);
    j++;
    i=-1;
    }

    }while(temp!=EOF);
    temp='\0';
    strcpy(wholefile[j],temp);
    j++;
    return j;
    }

    main(){
    char file[20];
    char wholefile[150][35];
    int record,k;
    printf("Enter file name:");
    gets(file);

    record=readwhole(wholefile,file);
    printf("%d",record);
    for(k=0;k<record;k++){
    printf("%s\n",wholefile[k]);
    }

    system("Pause");
    }


    I beg for help:oops:
    (btw, this is my first post here, if i violated any posting rules, please forgive me!)
    jeif_lee, Dec 4, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. msandlana
    Replies:
    0
    Views:
    2,390
    msandlana
    Apr 25, 2008
  2. newasp.net
    Replies:
    1
    Views:
    1,582
    imransyed63
    Aug 21, 2008
  3. pooja
    Replies:
    0
    Views:
    1,159
    pooja
    Mar 3, 2009
  4. amrutha0303
    Replies:
    0
    Views:
    960
    amrutha0303
    Aug 3, 2010
  5. amrutha0303
    Replies:
    0
    Views:
    2,100
    amrutha0303
    Aug 3, 2010
Loading...

Share This Page