C parse error

Discussion in 'Software' started by zoolander, Aug 26, 2003.

  1. zoolander

    zoolander Private E-2

    Hi there,

    I am new to C programming and I got stucked with this error.
    This is the code:

    #include <stdio.h>
    int main () {
    char* month[] = {" ", "Jan", "Feb", "March", "April", "May", "June",
    "July", "Aug", "Sept", "Oct", "Nov", "Dec"};
    int year;
    int day;
    int hour;
    int minute;
    int second;
    do {
    fprintf(stdout, "Enter date (year month day hour minute second): ");
    if(fscanf(stdin, "%i","%i", "%i", "%i", "%i", "%i", &year,month, &day, &hour,&minute, &second) == 6) {
    fprintf(stdout, "%d; %s; %d; %d; %d; %d\n", year, month, day, hour, minute,second);
    }
    }
    }

    Of course I still have not finished that code, but I already get this message:

    print_date.c: In function `main':
    print_date.c:18: parse error before '}' token

    I was wondering if someone would be able to see why I am getting this error.

    Thanks
     
  2. Vlad902

    Vlad902 Guest

    make char* month char *month and try making:

    " char* month[] = {" ", "Jan", "Feb", "March", "April", "May", "June",
    "July", "Aug", "Sept", "Oct", "Nov", "Dec"}; "

    " char *month[] = " ", "Jan", "Feb", "March", "April", "May", "June",
    "July", "Aug", "Sept", "Oct", "Nov", "Dec"; "

    And don't use fscanf, it does not do bounds checking so therefore it is vulnerable to buffer overflows....
     
    Last edited by a moderator: Aug 26, 2003

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