Thread: Urgent: Help needed.

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    8

    Angry Urgent: Help needed.

    Hi guys.

    I've got this program running but there're far too many errors and try as I might, I can't get the errors fixed.

    Anyone here mind helping me out? I'll show my program listing in the next reply.

    I would really appreciate any form of help .. thanks a million !

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    8
    **taken off**
    Last edited by Cn00b; 04-02-2003 at 10:20 PM.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    8
    The editing part isn't done yet as I'm still tryin to figure it out .. but if there's anyone out there who wouldn't mind helping a n00b like me, please please do help me out on the entire program.


  4. #4
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    first off all use code tags
    like this
    [ code ]
    actual code
    [ /code ]
    but then without spaces between code ,/code and the brackets.

    Then i havent took a look at everything but.
    ::edit::
    here was some code be4

    ::wooops::
    didnt saw this
    Code:
    #define FNAME "c:\\studrecords.dat"
    #define TEMPFNAME "c:\\temp.dat"
    that would make it simpler apparently you want to read from c:\\studrecords.dat by doing
    Code:
    studrecords=fopen("FNAME","r");
    this should be
    Code:
    FILE *studrecords;
    studrecords=fopen(FNAME,"r");
    /*notice that i didnt used any " around FNAME */
    Last edited by GanglyLamb; 04-02-2003 at 11:13 AM.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    8
    Thanks, GanglyLamb

    Anyway the fscan part is faulty.

    fscanf(studrecords, "%c %[^/]%*c %[^/]%*c %[^/]%*c %i", studname, studage, studsex, studaddress, studtel);

    Is this the right way to phrase it?

  6. #6
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    >>void main(void)
    this is wrong, main() only returns int, so change it to int main() then return a value at the end of the program.

    >>fprintf(studrecords, "%s,%i,$c,%s,%l \n",
    I'm not sure, but you don't mean %c?

    >>printf("File not found");
    betta' use the perror() function, it will display a real error message, giving the real problem.

    >>while(!feof(studrecords)&& Found == 0)
    this is wrong to.. check out this

    >>fflush(stdin);
    this is wrong, read this

    >>gets(nametosearch);
    gets is a evil and old function, it have's a lot of bugs, use instead

    fgets()

  7. #7
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    actually i dont get where you see any errors .. just went over to another comp to compile (my room) and there was only one error....
    somewhere dunno wich line guess youl have to search :d
    somewhere you have
    if(blabla=blablatrala)
    printf("tralala");
    else
    printf("brrrrrr");printf("lol");

    you need to put braces like this
    else{
    printf("dada");
    printf("brrr");
    }

    You use braces whenever u have more then a line after a statement(like with if and else and for blabla).

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    8
    Erm guys, the problem is with the program.

    Main Menu

    When I enter a choice outside range, the error message I set appears, thats fine. But when I enter a choice (within range of options), program exits.

    Deleting

    I think its gotta do with the fscan function, its wrong I think. When in the deleting screen, I will be prompted to enter a name of student to delete but whatever name I enter, it will display "Record Deleted" even when I entered a name that is not in the records.

    Search

    When in the search menu, 3 options will be given, 1 - 3. But whatever function I enter, the program just hangs.

    List all

    I think its the fscan function again. When the listall function is selected, a message "end of file..bla bla bla" appears.

    I sincerely thank all those who helped and are gonna offer me advices .. thanks a million.

    I'm gonna attach the edited codings of my program..

  9. #9
    Registered User
    Join Date
    Apr 2003
    Posts
    8
    **taken off**
    Last edited by Cn00b; 04-02-2003 at 10:19 PM.

  10. #10
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    You didn't fix what I told you... also, use code tags!
    Last edited by Vber; 04-02-2003 at 01:45 PM.

  11. #11
    Registered User
    Join Date
    Apr 2003
    Posts
    8
    Originally posted by Vber
    You didn't fix what I told you...
    what do you mean by code tags? my prog's working fine now except afew silly bugs

    thanks man

    but ive got a little problem here .. just a small one

    fprintf(studrecords, "%s,%s,%s,%s,%s", studname, studage, studsex, studaddress, studtel);

    This, it prints in the data file as -> name, age, sex+address, address again, tel.

    how do i correct it? it reads the sex and the address as a string and then the address again as a string eh?

    and my fscan isn't working

    fscanf(studrecords, "%c %[^/]*%c %[^/]*%c %[^/]*%c %i", studname, studage, studsex, studaddress, studtel);

    help, anyone?
    Last edited by Cn00b; 04-02-2003 at 02:12 PM.

  12. #12
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    >>what do you mean by code tags?
    read this

    >>afew silly bugs
    yes, but fix what I told you... it's important.

    >>fscanf(studrecords, "%c %[^/]*%c %[^/]*%c %[^/]*%c %i", studname, studage, studsex, studaddress, studtel);

    Well, decide, they're char or strings as you're trying to print them?

  13. #13
    Registered User
    Join Date
    Apr 2003
    Posts
    8
    Thanks again, Vber.

    Here are my codings again .. I still cannot figure out what is wrong, just can't get the fscan part working even though I've converted it all to read strings.

    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #include <ctype.h>
    #include <dos.h>
    #include <stdlib.h>

    #define FNAME "c:\\studrecords.txt"
    #define TEMPFNAME "c:\\temp.txt"

    void mainMenu();
    void addRecord();
    void editRecords();
    void deleteRecords();
    void searchRecords();
    void nameSearch();
    void telSearch();
    void displayRecords();
    void listallRecords();

    int choice, Found = 0; // Global Variables
    char studname[21], studage[3], studsex[1], studaddress[40], studtel[10], nametosearch[21], teltosearch[10];
    char ch, searchopt;

    FILE *studrecords, *temp;



    void listallRecords() // List all Records
    {
    if((studrecords = fopen("c:\\studrecords.txt","r")) == NULL)
    printf("File not found");
    else
    {
    clrscr();
    while(!feof(studrecords)&& Found == 0)
    {
    fscanf(studrecords, "%s %[^/]*%s %[^/]*%s %[^/]*%s %s", studname, studage, studsex, studaddress, studtel);
    if(feof(studrecords))
    break;
    printf("Name : %s\n", studname);
    printf("Age : %i\n", studage);
    printf("Sex : %c\n", studsex);
    printf("Address : %s\n", studaddress);
    printf("Tel No. : %i\n", studtel);
    }
    printf("End of file, press any key to return to previous menu");
    fclose(studrecords);
    getch();
    mainMenu();
    }
    }






    void searchRecords() // Searh functions and display of search results
    {
    studrecords=fopen("c:\\studrecords.txt","r");
    if (studrecords==NULL)
    printf("File Empty!");
    else
    {
    clrscr();
    gotoxy(30,11);
    printf("Search Options");
    gotoxy(30,13);
    printf("1. Name of student");
    gotoxy(30,14);
    printf("2. Telephone no. of student");
    gotoxy(30,15);
    printf("3. Exit to main menu");
    gotoxy(30,17);
    printf("Enter Choice [1-3]: ");
    choice=getch();

    printf("\n");
    switch(choice)
    {
    case '1':
    nameSearch();
    break;
    case '2':
    telSearch();
    break;
    case '3':
    mainMenu();
    break;
    default:
    gotoxy(30,20);
    printf("Invalid Option, please enter choice again [1-2]");
    break;

    }
    }
    getch();
    }

    void nameSearch(void)
    {
    clrscr();
    gotoxy(10,10);
    printf("Enter a name to search: ");
    fflush(stdin);
    gets(nametosearch);
    while(!feof(studrecords)&& Found == 0)
    {
    fscanf(studrecords, "%s %[^/]*%s %[^/]*%s %[^/]*%s %s", studname, studage, studsex, studaddress, studtel);
    if(strcmp(nametosearch,studname)==0)
    Found = 1;
    }
    if(Found)
    {
    displayRecords();
    }
    else
    {
    gotoxy(31,19);
    printf("Name not found!");
    gotoxy(31,18);
    printf("Search again? [Y/N]");
    scanf("%c", &searchopt);
    ch=toupper(getch());
    if (searchopt=='Y')
    nameSearch();
    else
    searchRecords();
    fclose(studrecords);
    }
    }

    void displayRecords() // Prints results of search
    {
    gotoxy(31,19);
    printf("Name : %s\n", studname);
    printf("Age : %i\n", studage);
    printf("Sex : %c\n", studsex);
    printf("Address : %s\n", studaddress);
    printf("Tel No. : %i\n", studtel);
    }





    void telSearch(void)
    {
    clrscr();
    gotoxy(10,10);
    printf("Enter a tel number to search: ");
    fflush(stdin);
    gets(teltosearch);
    while(!feof(studrecords)&& Found == 0)
    {
    fscanf(studrecords, "%s %[^/]*%s %[^/]*%s %[^/]*%s %s", studname, studage, studsex, studaddress, studtel);
    if(strcmp(teltosearch,studtel)==0)
    Found = 1;
    }
    if(Found)
    {
    displayRecords();
    }
    else
    {
    gotoxy(31,19);
    printf("Tel number not found!");
    gotoxy(31,18);
    printf("Search again? [Y/N]");
    scanf("%c", &searchopt);
    ch=toupper(getch());
    if (searchopt=='Y')
    telSearch();
    else
    searchRecords();
    fclose(studrecords);
    }
    }






    void deleteRecords() //Deletes Record
    {
    clrscr();
    temp=fopen("c:\\temp.txt", "w");
    if ((studrecords = fopen("c:\\studrecords.txt", "r")) == NULL)
    printf("File not found");
    else
    {
    printf("Enter name to delete: ");
    fflush(stdin);
    gets(nametosearch);
    while (!feof(studrecords))
    {
    fscanf(studrecords, "%s %[^/]*%s %[^/]*%s %[^/]*%s %s", studname, studage, studsex, studaddress, studtel);
    if (feof(studrecords))
    break;
    if (strcmp(nametosearch, studname) != 0)
    fprintf(temp,"%s %s %c %s %i\n", studname, studage, studsex, studaddress, studtel);
    else
    {
    Found = 1;
    printf("Name : %s\n", studname);
    printf("Age : %i\n", studage);
    printf("Sex : %c\n", studsex);
    printf("Address : %s\n", studaddress);
    printf("Tel No. : %i\n", studtel);
    }
    if(!Found)
    printf("Record not found!");
    }
    printf("Record deleted.");
    fclose(studrecords);
    fclose(temp);
    remove("c:\\studrecords.txt");
    rename("c:\\temp.txt", "c:\\studrecords.txt");

    }
    getch();
    mainMenu();
    }




    void addRecord() // Add a record
    {
    studrecords=fopen("c:\\studrecords.txt","a+");
    if (studrecords==NULL)
    { printf("Error!");
    exit(0);
    }

    else
    {
    clrscr();
    gotoxy(15,15);
    printf("Add New Record");
    gotoxy(15,16);
    printf("_______________");
    gotoxy(15,18);
    printf("Name: ");
    gets(studname);
    gotoxy(15,19);
    printf("Age: ");
    gets(studage);
    gotoxy(15,20);
    printf("Sex: ");
    gets(studsex);
    gotoxy(15,21);
    printf("Address: ");
    gets(studaddress);
    gotoxy(15,22);
    printf("Contact Number: ");
    gets(studtel);

    gotoxy(60,30);
    printf("\nSave Record? (Y/N)");
    ch=toupper(getch());
    if (ch=='Y')
    fprintf(studrecords, "%s,%s,%s,%s,%s", studname, studage, studsex, studaddress, studtel);
    fclose(studrecords);
    mainMenu();

    }


    }

    void mainMenu()
    {
    clrscr();
    gotoxy(10,10);
    printf("Almondvale Student Care Centre Database Administration System");
    gotoxy(25,15);
    printf("Press Any Key To Continue");
    getch();

    clrscr();
    gotoxy(34,9);
    printf("----------");
    gotoxy(35,10);
    printf("Main Menu");
    gotoxy(34,11);
    printf("----------");
    gotoxy(31,13);
    printf("1. Add Student Record");
    gotoxy(31,14);
    printf("2. Edit Student Details");
    gotoxy(31,15);
    printf("3. Delete Student");
    gotoxy(31,16);
    printf("4. Search Records");
    gotoxy(31,17);
    printf("5. List all records");
    gotoxy(31,18);
    printf("6. Exit Program");
    gotoxy(31,21);
    printf("Enter Choice [1-6]: ");
    choice=getch();

    printf("\n");
    switch(choice)
    {
    case '1':
    addRecord();
    break;
    case '2':
    editRecords();
    break;
    case '3':
    deleteRecords();
    break;
    case '4':
    searchRecords();
    break;
    case '5':
    listallRecords();
    break;
    case '6':
    clrscr();
    gotoxy(10,10);
    printf("Thank you for using the Almondvale Student Care Centre Database Administration System");
    gotoxy(25,15);
    printf("Goodbye!");
    exit(0);
    break;
    default:
    gotoxy(25,25);
    printf("Invalid Option, please enter choice again [1-6]");
    break;
    }
    getch();
    }

    void main(void)
    {
    mainMenu();

    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent Help Needed In Writing Algorithm!!
    By Vikramnb in forum C++ Programming
    Replies: 1
    Last Post: 01-09-2009, 12:46 PM
  2. Help needed with program - urgent thanks!
    By lildevil in forum C Programming
    Replies: 1
    Last Post: 03-09-2008, 06:45 AM
  3. Urgent help needed!!!
    By gibs21 in forum C Programming
    Replies: 2
    Last Post: 09-26-2002, 01:45 PM
  4. Help Needed: Borland C++ 5.5 Installation - URGENT!
    By Linette in forum C++ Programming
    Replies: 12
    Last Post: 03-09-2002, 06:44 PM