C++ problem.. plz help guys

Discussion in 'Software' started by ke3pup, Jun 16, 2005.

  1. ke3pup

    ke3pup Private E-2

    hi guys:

    im new in C++ and im stuck here with no clue how to fix it.

    this is the code i wrote, which is to open a file, and read into it, it also count how many 'F' or 'M' occur. BUT i want to put gender 'M' pr 'F' in the varable i named "gender" and also i want to put the next 2 numbers in "age" and last number in "lead".

    this is becuase later on i have to put diffrent people in diffrent category based on their age, lead and gender.

    so this is the code:

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

    void main()
    {
    FILE *read;
    char ch;
    int countm , countf;
    int age, lead;
    char gender;


    countm = 0;
    countf = 0;

    read= fopen("c:\\c\\custsurvey1.txt", "r");

    if(read==NULL)
    {
    printf("Error reading file");
    }

    else
    {
    fscanf(read," %c %d %d", &gender, &age, &lead);
    for(ch=char getc(read); ch !=EOF; ch=char getc (read))
    {
    printf("%c", ch);

    if(ch == 'F')
    {

    countf++;
    }

    else
    {
    if(ch == 'M')

    countm++;
    }

    }

    if(fclose(read) ==EOF)
    puts("cannot close file");

    }

    printf("\nThe Female count is %d", countf);
    printf("\nTHe male count is %d", countm);

    getch();
    }


    The problem is when this line "fscanf(read," %c %d %d", &gender, &age, &lead);" is included the first line of characters don;t appear, it starts from the second line! i don;t seem to be able to fix that. can anyone help me plzzz. i've attached the file. plz help thanx
     

    Attached Files:


MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds