#include<stdio.h>
#include<string.h>
#include<conio.h>
#define SIZE 21
#define MAX 10

int id[MAX];
int idn[MAX];
char fn[MAX][SIZE];
char ln[MAX][SIZE];
char mi[MAX][SIZE];
int q1;
int q2;
int q3;
float ave;

 int menu()
 { int i,s=0;

  while(s<1|| s>4) 
   {
    clrscr();
    gotoxy(5,5);
    printf("menu");
    gotoxy(5,7);
      printf("1.insert");
    gotoxy(5,9);
      printf("2.delete");
    gotoxy(5,11);
     printf("3.Display all");
    gotoxy(5,13);
     printf("4.Quit");
    gotoxy(5,15);
     printf("Select(1-4): ");
     scanf("%d",&s);
   }
    return (s);
 }

 void insert(int idn,char fn[MAX],char ln[MAX],char mi[2],int q1,int q2,int q3,float ave,int id[MAX])
 {
  int i,p;
  i=p=0;
  while(idn>id[i] && id[i]!=-1)
     i++;
  p=i;
  if(id[p]==-1)
    {
     id[p]=idn;
     strcpy(fn[p],fn);
     strcpy(ln[p],ln);
     strcpy(mi[p],mi);
     q1[p]=q1;
     q2[p]=q2;
     q3[p]=q3;
     ave[p]=ave;
     }
  else{
     for(i=end(id);i>p;i--)
      {
     id[i]=id[i-1];
     strcpy(fn[i],fn[i-1]);
     strcpy(ln[i],ln[i-1]);
     strcpy(mi[i],mi[i-1]);
     q1[i]=q1[i-1];
     q2[i]=q2[i-1];
     q3[i]=q2[i-1];
     ave[i]=ave[i-1];
      }

       id[p]=idn;
       strcpy(fn[p],fn);
       strcpy(ln[p],fn);
       strcpy(mi[p],mi);
       q1[p]=q1;
       q2[p]=q2;
       q3[p]=q3;
       ave[p]=ave;

       }

  void initialize(int idn,char fn[MAX],char ln[MAX],char mi[2],int q1,int q2,int q3,float ave,int id[MAX])
  {
    int i=0;
    for(i=0;i<MAX;i++)
      {
       id[i]=-1;
       fn[i]=-1;
       ln[i]=-1;
       mi[i]=-1;
       q1[i]=-1;
       q2[i]=-1;
       q3[i]=-1;
       ave[i]=-1;
      }

   }

   int end(int idn,char fn[MAX],char ln[MAX],char mi[2],int q1,int q2, int q3, float ave,int id[MAX])
    {
    int i=0;
        while(id[i]!=-1)
           i++;
         return(i);
    }

   void delete(int idn,char fn[MAX],char ln[MAX],char mi[2],int q1,int q2, int q3, float ave,int id[MAX])
    {
        int i,p;
        p=locate(idn,id);

         if(p<0)
             {
           printf("record not found");
           getch();
           exit(0);
             }
          else
             {
              for(i=p;i<end(id);i++)
                 {
                  id[i]=id[i+1];
                  fn[i]=fn[i+1];
                  ln[i]=ln[i+1];
                  mi[i]=mi[i+1];
                  q1[i]=q1[i+1];
                  q2[i]=q2[i+1];
                  q3[i]=q3[i+1];
                  }
              }
      }

     int locate(int idn,char fn[SIZE],char ln[SIZE],char mi[SIZE],int q1,int q2, int q3, float ave, int id[MAX])
      {
         int i=0;
           while(x!=id[i] && id[i]!=-1)
                    i++;

            if(id[i]==-1)
               return(-1);
            else
                return(i);
       }

       void displayall(int id[MAX])
         {
           int i;
           for(i=0;i<end(id);i++)
               {
                printf("\n%d %d",i+1,id[i]);
                getch();
               }
         }


 main()
  {
 int i;
 initialize(id);
 while(1){
   i=menu();
   switch(i){
   case 1: clrscr();
       prinf("\nInput id number: ");scanf("%d",&idnum);
       prinf("\nInput first name: ");scanf("%s",&fnm);
       prinf("\nInput last name: ");scanf("%d",&lnm);
       prinf("\nInput middle initial: ");scanf("%d",&min);
       prinf("\nInput quiz 1: ");scanf("%d",&qz1);
       prinf("\nInput quiz 2: ");scanf("%d",&qz2);
       prinf("\nInput quiz 3: ");scanf("%d",&qz3);
       ave=(qz1+qz2+qz3)/3.0;
       prinf("%d",aver);
       insert(idnum,fnm,lnm,min,qz1,qz2,qz3,aver,id);break;
    case 2:
        clrscr();
            printf("\nInput id number: ");scanf("%d",&idn);
            delete(idn,id)
            break;
    case 3:
            clrscr();displayall(id);break;
    case 4:
            exit(0);
             }
   getche();
          }
   }

please help me!! about this code i've created!!
i really don't know what to do!!
I have so many errors some of those errors are:
1. invalid indirection in function insert
2. non portable pointer conversion in function insert
3. parameters q1,q2,q3 are not used in function insert

this program is about creating a list in which user can select in the menu to insert,delete or display all the data inputed.

the user should input the following if they want to add another in the list.
these are:

student number,last name,first name, middle name, quiz1,quiz2,quiz3,average of the quizes

these should appear
and must be in a parrallel arrays!

COULD SOMEONE HELP ME??!!!! PLS

what compiler are you using? my guess is Turbo C, but I could easily be wrong.

As for unused variables -- just delete them from the program.

>> strcpy(fn[p],fn);

fn is a character array, fn[p] is a single character somewhere in that array. strcpy() expects the first parameter to be a pointer to the destination string. Instead your program is just passing a single character.

#include<stdio.h>
#include<string.h>
#define SIZE 5
#define MAX 100

int id[MAX];
char fn[MAX][SIZE];
char f[MAX];
char l[MAX];
char ln[MAX][SIZE];
char mi[MAX][SIZE];
char m[MAX];

 int menu()
 { 
   int i,s=0;

  while(s<1|| s>4)
  {
     clrscr();
     gotoxy(5,5);
     printf("menu");
     gotoxy(5,7);
     printf("1.insert");
     gotoxy(5,9);
     printf("2.delete");
     gotoxy(5,11);
     printf("3.Display all");
     gotoxy(5,13);
     printf("4.Quit");
     gotoxy(5,15);
     printf("Select(1-4): ");
     scanf("%d",&s);
   }
    return (s);
 }

 void insert(int idn,int id[MAX],char fn[MAX],char f[MAX],char ln[MAX],char l[MAX],char mi[MAX],char m[MAX])
 {
  int i,p;
  i=p=0;
  while(idn>id[i] && id[i]!=-1)
     i++;
  p=i;
  if(id[i]==-1)
    {
     id[p]=idn;
     strcpy(f[i],fn);
     strcpy(l[i],ln);
     strcpy(m[i],mi);
     }

  else
    {
     for(i=end(id);i>p;i--)
     {
       id[i]=id[i-1];
       strcpy(f[i],f[i-1]);
           strcpy(l[i],l[i-1]);
       strcpy(m[i],mi[i-1]);
       }


      }
  }
  void initialize(int id[MAX])
  {
    int i=0;
    for(i=0;i<MAX;i++)
      {
       id[i]=-1;
       f[i]=-1;
        l[i]=-1;
        m[i]=-1;
      }
   }

   int end(int id[MAX])
    { int i=0;
        while(id[i]!=-1)
           i++;
         return(i);
    }

   void delete(int idn,int id[MAX])
    {
        int i,p;
    p=locate(idn,id);

         if(p<0){
           printf("record not found");
           getch();
           exit(0);
           }
          else
          for(i=p;i<end(id);i++)
             {
                  id[i]=id[i+1];
        strcpy(fn[i],fn[i+1]);
                strcpy(ln[i],ln[i+1]);
         strcpy(mi[i],mi[i+1]);
             }
       }

     int locate(int idn,int id[MAX])
     {int i=0;
           while(idn!=id[i] && id[i]!=-1)
                    i++;

            if(id[i]==-1)
               return(-1);
            else
                return(i);
       }

       void displayall(int id[MAX],char f[MAX],char l[MAX],char m[MAX])
         {
           int i;
       for(i=0;i<end(id);i++)
          {
        gotoxy(5,5);
        printf("       idnum    fname     lstnme    midntl");
        gotoxy(7,9+i);
        printf("  %d   %d         %s         %s         %s ",i+1,id[i],f[i],l[i],m[i]);
        getch();
               }
       }


 main()
  {
 int i,idn;
 char fn[MAX];
  char ln[MAX];
   char mi[MAX];
 initialize(id);
 while(1){
   i=menu();
   switch(i){
   case 1: clrscr();
       printf("\nInput number: ");scanf("%d",&idn);
       printf("\nInput first name: ");scanf("%s",&fn);
           printf("\nInput last name: ");scanf("%s",&ln);
           printf("\nInput middle initial: ");scanf("%s",&mi);
       insert(idn,id,fn,f,ln,l,mi,m);break;
    case 2:
        clrscr();
        printf("\nInput number: ");scanf("%d",&idn);
        delete(idn,id);break;
    case 3:
        clrscr();displayall(id,f,l,m);break;
    case 4:
            exit(0);
      }
   getche();
  }
 }
#include<stdio.h>
#include<string.h>
#define SIZE 5
#define MAX 100

int id[MAX];
char fn[MAX][SIZE];
char f[MAX];
char l[MAX];
char ln[MAX][SIZE];
char mi[MAX][SIZE];
char m[MAX];

 int menu()
 { 
   int i,s=0;

  while(s<1|| s>4)
  {
     clrscr();
     gotoxy(5,5);
     printf("menu");
     gotoxy(5,7);
     printf("1.insert");
     gotoxy(5,9);
     printf("2.delete");
     gotoxy(5,11);
     printf("3.Display all");
     gotoxy(5,13);
     printf("4.Quit");
     gotoxy(5,15);
     printf("Select(1-4): ");
     scanf("%d",&s);
   }
    return (s);
 }

 void insert(int idn,int id[MAX],char fn[MAX],char f[MAX],char ln[MAX],char l[MAX],char mi[MAX],char m[MAX])
 {
  int i,p;
  i=p=0;
  while(idn>id[i] && id[i]!=-1)
     i++;
  p=i;
  if(id[i]==-1)
    {
     id[p]=idn;
     strcpy(f[i],fn);
     strcpy(l[i],ln);
     strcpy(m[i],mi);
     }

  else
    {
     for(i=end(id);i>p;i--)
     {
       id[i]=id[i-1];
       strcpy(f[i],f[i-1]);
           strcpy(l[i],l[i-1]);
       strcpy(m[i],mi[i-1]);
       }


      }
  }
  void initialize(int id[MAX])
  {
    int i=0;
    for(i=0;i<MAX;i++)
      {
       id[i]=-1;
       f[i]=-1;
        l[i]=-1;
        m[i]=-1;
      }
   }

   int end(int id[MAX])
    { int i=0;
        while(id[i]!=-1)
           i++;
         return(i);
    }

   void delete(int idn,int id[MAX])
    {
        int i,p;
    p=locate(idn,id);

         if(p<0){
           printf("record not found");
           getch();
           exit(0);
           }
          else
          for(i=p;i<end(id);i++)
             {
                  id[i]=id[i+1];
        strcpy(fn[i],fn[i+1]);
                strcpy(ln[i],ln[i+1]);
         strcpy(mi[i],mi[i+1]);
             }
       }

     int locate(int idn,int id[MAX])
     {int i=0;
           while(idn!=id[i] && id[i]!=-1)
                    i++;

            if(id[i]==-1)
               return(-1);
            else
                return(i);
       }

       void displayall(int id[MAX],char f[MAX],char l[MAX],char m[MAX])
         {
           int i;
       for(i=0;i<end(id);i++)
          {
        gotoxy(5,5);
        printf("       idnum    fname     lstnme    midntl");
        gotoxy(7,9+i);
        printf("  %d   %d         %s         %s         %s ",i+1,id[i],f[i],l[i],m[i]);
        getch();
               }
       }


 main()
  {
 int i,idn;
 char fn[MAX];
 char ln[MAX];
 char mi[MAX];
 initialize(id);
 while(1)
 {
   i=menu();
   switch(i)
    {

   case 1: clrscr();
       printf("\nInput number: ");scanf("%d",&idn);
       printf("\nInput first name: ");scanf("%s",&fn);
           printf("\nInput last name: ");scanf("%s",&ln);
           printf("\nInput middle initial: ");scanf("%s",&mi);
       insert(idn,id,fn,f,ln,l,mi,m);break;

    case 2:
        clrscr();
        printf("\nInput number: ");scanf("%d",&idn);
        delete(idn,id);break;

    case 3:
        clrscr();displayall(id,f,l,m);break;

    case 4:
            exit(0);
      }

   getche();
  }
 }

i have somewhat found a solution in my program. But there are still some problem in my displayall function. coz when i'm running my program the firstname,lastname and middle initial outputs are all the same. even though i assign it differently. like when i assigned firstname as 'Dave', lastname 'Smith' and mid initial as 'B' it will just give an output of D in all the 3.

what can i do to get 3 different outputs?
pls someone help me

id, f, l, and m are all arrays. id is an int array which may contain up to MAX = 100 ints. The first int in id is id[0], the second is id[1], the third is id[2], etc. f, l, and m are char arrays. If the char array is null terminated then f, l, and m are Cstyle strings. The first char in f is f[0], the second char in f is f[1], etc, very similar to each int in id. However, if you want to display a string then you don't display a single char, unless the string is just one char long. Therefore, this:

printf(" %d %d %s %s %s ",i+1,id,f,l,m);

should probably be more like this:

printf(" %d %d %s %s %s ",i+1,id,f,l,m);

Now if what's in f, l, m are the same the output should be the same, and if they aren't the same, then the output shouldn't be the same. If they are the same string and you don't want them to be, then the protocol used to assign data to them is in error.

Buddy you have got too many errors hanging out there in your code and even your logic is a bit wrong there.

>>>

strcpy(f[i],f[i-1]);

strcpy is used to copy contents from one character array to another. IF you just want to change the char value y not use the assignment stmt. Or do you reallly wnt to copy the character array contents? We have no way of knowing it.

>>>

void delete(int idn,int id[MAX])

delete is a reserved keyword used to free the memory block pointed by a pointer. This is a violation.

Basically i think you are confusing yourself between character and character arrays called as strings. Read some good articles so that your basics are a bit clear.

Hope it helped. Bye.

thanks 4 those who replied! I'm somehow debug my program a lil'bit but there are still some problems. here is my new code wherein I added some more...(like q1,q2,q3 etc....)

#include<stdio.h>
#include<string.h>
#define SIZE 5
#define MAX 10

int id[MAX];
char fn[MAX][SIZE];
char f[MAX];
char l[MAX];
char ln[MAX][SIZE];
char mi[MAX][SIZE];
char m[MAX];
int q1[MAX];
int q4[MAX];
int q2[MAX];
int q5[MAX];
int q3[MAX];
int q6[MAX];

 int menu()
 {
   int i,s=0;

  while(s<1|| s>4)
  {
     clrscr();
     gotoxy(5,5);
     printf("menu");
     gotoxy(5,7);
     printf("1.insert");
     gotoxy(5,9);
     printf("2.delete");
     gotoxy(5,11);
     printf("3.Display all");
     gotoxy(5,13);
     printf("4.Quit");
     gotoxy(5,15);
     printf("Select(1-4): ");
     scanf("%d",&s);
   }
    return (s);
 }

 void insert(int idn,int id[MAX],char fn[MAX],char f[MAX],char ln[MAX],char l[MAX],char mi[MAX],char m[MAX],int q1[MAX],int q4[MAX],int q2[MAX],int q5[MAX],int q3[MAX],int q6[MAX])
 {
  int i,p;
  i=p=0;
  while(idn>id[i] && id[i]!=-1)
     i++;
  p=i;
  if(id[i]==-1)
    {
     id[p]=idn;
     strcpy(f[i],fn);
     strcpy(l[i],ln);
     strcpy(m[i],mi);
     q4[i]=q1;
     q5[i]=q2;
     q6[i]=q3;
     }

  else
    {
     for(i=end(id);i>p;i--)
     {
       id[i]=id[i-1];
       strcpy(f[i],f[i-1]);
           strcpy(l[i],l[i-1]);
       strcpy(m[i],m[i-1]);
           q4[i]=q4[i-1];
           q5[i]=q5[i-1];
           q6[i]=q6[i-1];
       }


      }
  }
  void initialize(int id[MAX])
  {
    int i=0;
    for(i=0;i<MAX;i++)
      {
       id[i]=-1;
       f[i]=-1;
        l[i]=-1;
        m[i]=-1;
        q4[i]=-1;
        q5[i]=-1;
        q6[i]=-1;
      }
   }

   int end(int id[MAX])
    { int i=0;
        while(id[i]!=-1)
           i++;
         return(i);
    }

   void delete(int idn,int id[MAX])
    {
        int i,p;
    p=locate(idn,id);

         if(p<0){
           printf("record not found");
           getch();
           exit(0);
           }
          else
          for(i=p;i<end(id);i++)
             {
                  id[i]=id[i+1];
        strcpy(f[i],f[i+1]);
                strcpy(l[i],l[i+1]);
         strcpy(m[i],m[i+1]);
                q4[i]=q4[i+1];
                q5[i]=q5[i+1];
                q6[i]=q6[i+1];
             }
       }

     int locate(int idn,int id[MAX])
     {int i=0;
           while(idn!=id[i] && id[i]!=-1)
                    i++;

            if(id[i]==-1)
               return(-1);
            else
                return(i);
       }

 void displayall(int id[MAX],int idn[MAX],char f[MAX],char fn[MAX],char l[MAX],char ln[MAX],char m[MAX],char mi[MAX],int q1[MAX],int q4[MAX],int q2[MAX],int q5[MAX],int q3[MAX],int q6[MAX])
         {
           int i;
       for(i=0;i<end(id);i++)
          {
        gotoxy(5,5);
        printf("       idnum   fname  lstnme   midntl     q1      q2      q3");
        gotoxy(7,9+i);
        printf(" %d     %d       %s      %s       %s        %d        %d      %d",i+1, id[i], fn, ln, mi,q1[i],q2[i],q3[i]);
        getche();
               }
       }


 main()
  {
 int i,idn;
 char fn[MAX][SIZE];
  char ln[MAX][SIZE];
   char mi[MAX][2];
 int q1[MAX];
 int q4[MAX];
 int q2[MAX];
 int q5[MAX];
 int q3[MAX];
 int q6[MAX];
 initialize(id);
 while(1){
   i=menu();
   switch(i){
   case 1: clrscr();
       printf("\nInput  number: ");scanf("%d",&idn);
       printf("\nInput first name: ");scanf("%s",&fn);
           printf("\nInput last name: ");scanf("%s",&ln);
           printf("\nInput middle initial: ");scanf("%s",&mi);
           printf("\nInput  quiz 1: ");scanf("%d",&q1);
           printf("\nInput   quiz 2:");scanf("%d",&q2);
           printf("\nInput   quiz 3:");scanf("%d",&q3);
       insert(idn,id,fn,f,ln,l,mi,m,q1,q4,q2,q5,q3,q6);break;
    case 2:
        clrscr();
        printf("\nInput number: ");scanf("%d",&idn);
        delete(idn,id);break;
    case 3:
        clrscr();displayall(id,idn,f,fn,l,ln,m,mi,q1,q4,q2,q5,q3,q6);break;
    case 4:
            exit(0);
      }
   getche();
  }
 }

in this code i've created i've somehow solved my previous problem wherein I've already got a different output(in the 3 array of strings) unlike before.
BUT now my problem is, when i try to add another inputs using the insert function. It just display the second output.

Edited 3 Years Ago by Reverend Jim: Fixed formatting

here is an example of what i'm talking about:

my first inputs are:
idnum: 2
firstname: dave
lastname: smith
middle initial: s
quiz 1: 1
quiz 2: 2
quiz 3: 3

my second inputs are:
idnum: 2
firstname: daniel
lastname: howard
middle initial: q
quiz 1: 2
quiz 2: 5
quiz 3: 6

but it will give an output like this:


idnum fname lstnme midntl q1 q2 q3
1 1 daniel howard q 2 5 6
2 2 daniel howard q 0 0 0


instead of:


idnum fname lstnme midntl q1 q2 q3
1 1 dave smith s 1 2 3
2 2 daniel howard q 2 5 6


how can I solve this problem??

This article has been dead for over six months. Start a new discussion instead.