file writting & loop problem

This is a discussion on file writting & loop problem within the C Programming forums, part of the General Programming Boards category; My problems are these, what my program should do is read in from a file scmemail.txt, and write out to ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    6

    Unhappy file writting & loop problem

    My problems are these, what my program should do is read in from a file scmemail.txt, and write out to a file email.txt I've had this working but have lost it.

    I also need to call a function make_name to tokenise lines in the file and then store the tokenised array of strings (last_name[i]) what i want to do is print out these strings in a loop but I can't get it to work, if I print out the strings and reference them last_name_[1],2 etc this works. but cannot get it to work in loop.

    Can anybody help, I,ve include the file I'm working with any help would be greatly appreciated.

    Thank you

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

    FILE *ofp;
    char *make_name(char *s);
    char *a[20], *p, *name;
    char *last_name[40];
    int i;
    int main()
    {
    char buffer [101], s[101];
    char new_name[30]="";
    FILE *ifp, *ofp;

    if ((ifp=fopen("scmemail.txt", "r")) == NULL)
    printf("The file scmemail.txt could't be opened or is corrupt'/n'");

    if ((ofp=fopen("email.txt", "w")) == NULL)
    printf("The file email.txt couldn't be opened for writting please check disk space'/n'");

    while(fgets(buffer,101,ifp)!=NULL)
    {
    strcpy(s, buffer);
    switch(buffer[0])
    {
    case'#':break;

    case'&'rintf(" here now\n"); /*visual check*/
    name=make_name(s);/*Call to function make_name*/
    strcpy(new_name,name);
    break;


    }

    }

    fputs(name,ofp);
    fclose(ifp);
    fclose(ofp);

    return 0;
    }

    char *make_name(char *s)
    {
    char *kurt;
    // char *last_name[40];
    int Count;

    Count=0;
    i=0;
    kurt=strtok(s," &");

    while(*kurt != '-')
    {
    last_name[i++]=kurt;

    kurt=strtok(NULL," ");
    }

    for (Count=1;Count<i;Count++)
    {
    fputs(last_name[i],stdout);
    }
    printf(last_name[i]);


    // fputs(last_name[0],stdout);
    // fputs(last_name[1],stdout);
    // fputs(last_name[2],stdout);

    return s;
    } /* end of make_name function */
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  3. Problem reading file
    By coder_009 in forum C Programming
    Replies: 10
    Last Post: 01-15-2008, 12:22 PM
  4. File I/O problem
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 12
    Last Post: 09-03-2005, 12:14 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

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