Thread: I got a problem with my code, can anyone help?

  1. #1
    Registered User
    Join Date
    Jul 2016
    Posts
    8

    I got a problem with my code, can anyone help?

    so the question tells me to create something like an address book. It uses switch case.

    It acquires me to do the following things:

    1) if the user enter 'i', it allows the user to enter it's name, phone number and email.
    2) when the user enters 'l', it's suppose to list all of the saved data on the file.
    3) when 's' is entered, it suppose to save the data entered in 'i'. when 's' is entered is suppose to be able to save all of the previously entered data.
    4) when 'o' is entered, its suppose to read the previously saved data.
    5) when 'c' is entered, it suppose to clear all the saved data.
    6) when 'q' is entered, it should quit the program.

    the program should be able to save the data of up to 50 people.

    Please help, much thanks.


    Code:
    #include<stdio.h>
    #include<ctype.h>
    #include<string.h>
    #include<stdlib.h>
    #define NAME 50
    #define PHONE 20
    #define EMAIL 20
    
    
    
    
    
    
    struct Information{
     char name [NAME];
     int phone [PHONE];
     char email[EMAIL];
    };
    //check whether it is operator1 or operator 1
    /*insert(){
     char operator1;
     do{
      
      
     }
    }
    */
    
    
    FILE *temp;
    FILE *Addressbook;
    
    
    int main()
    {
     char operator;
     int count = 0;
     while (1){
      printf ("Welcome, enter letter.\ni for info, l to list, s to save the file and its name, o for read a paticular file, q for quit, max 50 people.");
      scanf ("%c", &operator);
      switch (operator){
         case 'i':
          //Addressbook = fopen ("Addressbook.txt", "a+");
          //what's the a+
          printf ("enter name, phone and email\n");
          scanf ("%s", Information.name);
          scanf ("%d", Information.phone);
          scanf ("%s", Information.email);
          count = count + 1;
         break;
         case 'l':
          for (b=0; b<count; b++)
           printf ("No. %:\n", b);
           printf ("Name: %s\n", Information.name);
           printf ("Phone: %d\n", Information.phone);
           printf ("%Email: %s\n", Information.email);
           printf ("=================\n");
         break;
         case 's':
          save();
         break;
         case 'o':
          list_saved();
         case 'q':
          printf ("Quiting program");
          return (0);
         break;
      }
     
      system("pause"); 
      system ("cls"); 
     }
     return 0;
    }

  2. #2
    Registered User
    Join Date
    Jul 2016
    Posts
    8
    By the way, its the Information.name and other which don't work. Help would be very much appreciated!

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    FYI: "Information" in your program is a type; it is NOT a variable.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem or compiler problem....?
    By miloki in forum C Programming
    Replies: 4
    Last Post: 03-05-2015, 12:48 AM
  2. problem in code
    By Damienmc++keown in forum C++ Programming
    Replies: 4
    Last Post: 04-20-2011, 05:50 PM
  3. Same problem, different code
    By SOS MAR in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2011, 11:41 AM
  4. Problem with my code :( please help
    By yrostran in forum C Programming
    Replies: 4
    Last Post: 11-29-2006, 04:22 PM
  5. Code problem
    By dot_rain in forum C Programming
    Replies: 1
    Last Post: 11-21-2003, 04:30 PM

Tags for this Thread