Swicthing data orders...

This is a discussion on Swicthing data orders... within the C Programming forums, part of the General Programming Boards category; Ok, My progs, read data in a file, show content on screen, and now It must save data in another ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    14

    Swicthing data orders...

    Ok,

    My progs, read data in a file, show content on screen, and now It must save data in another files but in a different orders( the last will be the first record and the first the last....) well here my code....

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

    FILE * ptrPerson;
    FILE * ptrOutput;

    struct Employe {
    char prenom[20];
    char nom[20];
    }Names[7];

    struct Employe Remplir(struct Employe Temp);
    void afficher(struct Employe Temp);
    void enregistrer(struct Employe Temp);
    int cnt;

    main()
    {
    printf("Le programme va maintenant lire les données contenu dans le fichier person.dat\n");
    /*open file and read data*/
    if ((ptrPerson=fopen("person.dat","r+b"))==NULL)
    {
    printf("\nErreur: le fichier n'a pu être ouvert.\n");
    exit(1);
    }
    else
    {
    for(cnt=0;cnt<7;cnt++){
    Names[cnt]=Remplir(Names[cnt]);
    }
    /* show data on screen*/
    for (cnt=0;cnt<7;cnt++){
    afficher(Names[cnt]);
    }


    }
    /*Save it in oppossite order*/
    if ((ptrOutput=fopen("output.dat","w+b"))==NULL)
    {
    printf("\nErreur: le fichier n'a pu être ouvert.\n");
    exit(1);
    }
    else
    {
    for(cnt=6;cnt<=0;cnt--){
    enregistrer(Names[cnt]);
    }
    }
    fclose(ptrPerson);
    fclose(ptrOutput);
    return 0;
    }

    struct Employe Remplir(struct Employe Temp){
    fscanf(ptrPerson,"%s%s\n",Temp.nom,Temp.prenom);
    return(Temp);
    }



    void afficher(struct Employe Temp){

    printf("%s %s\n",Temp.nom,Temp.prenom);
    }

    void enregistrer(struct Employe Temp){

    fprintf(ptrOutput,"%s %s\n",Temp.nom,Temp.prenom);
    }




    my trouble is here:

    for(cnt=6;cnt<0;cnt--){
    enregistrer(Names[cnt]);
    }

    ***********
    void enregistrer(struct Employe Temp){

    fprintf(ptrOutput,"%s %s\n",Temp.nom,Temp.prenom);
    }


    I thought it will work, but It just write nothing in my file...

    any hints will be appreciated...

    thanks


    OH and at each function, I must warn user what the progs do..

    like
    printf("The progs is reading data\n");

    but if I want to make the progs pause until user press a key, how do I do that....???
    Last edited by Mars_Volta; 04-25-2002 at 07:26 AM.

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > any hints will be appreciated...

    Use code tags for more help!!
    The world is waiting. I must leave you now.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    14
    Originally posted by Shadow
    > any hints will be appreciated...

    Use code tags for more help!!
    yeah I know sorry, but mine a re in french...i'll do it i na few when i'll have 2 sec

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    You were testing that cnt was less than 0, but that is the stopping condition. You want to test that cnt is greater than or equal to 0.
    Code:
    for(cnt=6; cnt>=0; cnt--){ 
      enregistrer(Names[cnt]); 
    }
    >but if I want to make the progs pause until user press a key, how do I do that
    Ask for input but don't assign it to anything:
    Code:
    puts ( "Press any key to continue" );
    getchar();
    -Prelude
    My best code is written with the delete key.

  5. #5
    Unregistered
    Guest
    thx a lot Prelude, you are really helpfull...hope one day i'll be the one who will help you out...(but it seem like it gonna be in a while...)


    Mars Volta

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM

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