For laeuchli only...

anyone else .. don't even try, Jesse has some code already and i just want him to fix it for me :)

jesse ... email me the source code... and make it as commented as possible within reason (e.g. comment the libraries as to what they , and the functions you will call from them... what each function you use does... and the major variables)
and make it standard C.. i don't want <win_specific.h) in there :)

ok, specs:

1) Menu that lists following:
      a) Load file? (print to screen)
      b) input new ?
      c) clear file?
      d) quit
      you don't have to use letters

A) pretty obvious... you print it.. it says press whatever to go back to menu... yada  yada...

B)
      1)prompts user to input First             name and then Last
      2) Then Phone Number
      3) ask usr if they are sure (shows what they typed... ) and then write to file
      4) reorganized file in alphabetical last name order

C) clears file... probably just erases it... i don't know.. will the program make a new one if something says write to it? that is your problem :)

D) quits

everything but D has to come back to the menu...

that is it man... thanks again...

email the source to me... i am not in windoze so the EXE won't help me much


David
djtanseyAsked:
Who is Participating?
 
laeuchliConnect With a Mentor Commented:
/***************************************************************************
                          main.cpp  -  description
                             -------------------
    begin                : Mon Feb 28 11:52:34 EST 2000

    copyright            : (C) 2000 by Jesse Laeuchli
    email                : jesse@laeuchli.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char switchint[2];
char filename[256];
char name[81]="";
FILE *database;
char* filelist[81];//Max number of entries for the database file.
struct savechar{char holder[81];};
savechar orderit[81];
long totalpos=0;
long ourpos=0;
long ourpos2=0;
void mainmenu();
int compare( const void *arg1, const void *arg2 )  //I  need this for qsort
{
   /* Compare all of both strings: */
   return strcmp( * ( char** ) arg1, * ( char** ) arg2 );
}

void  getaline(char parm[81])
{
   char buffer[81];
   int i, ch;


   /* Read in single line from "stdin": */
   for( i = 0; (i < 80) &&  ((ch = getchar()) != EOF)
                        && (ch != '\n'); i++ )
      buffer[i] = (char)ch;

   /* Terminate string with null character: */
   buffer[i] = '\0';
  strcpy(parm,buffer);
}
void  getalinefromafile(char parm[81])
{
   char buffer[81];
   int i, ch;


      for( i = 0; (i < 80) &&  ((ch = getc(database)) != EOF)
                        && (ch != '\n'); i++ )
      buffer[i] = (char)ch;

   /* Terminate string with null character: */
   buffer[i] = '\0';
  strcpy(parm,buffer);

}
void Caseone()
{
int loopis=0;
char phone[81]="";
char name[81]="";
char lastname[81]="";
char firstname[40]="";
printf("Type in name:\n");
getaline(name);
char testit=' ';
int i=0;
int howmanyjunk=0;
do{ //This moves the names around.
if(name[i]!=32)//32 is a space
{
firstname[i]=name[i];
name[i]=' ';
howmanyjunk++;
}
else
{
loopis=1;
}
i++;
}while(loopis==0);
i=0;
loopis=0;
do{
lastname[i]=name[i+howmanyjunk+1];
i++;
}while(i<81);//81 is max
strcat(lastname,",");
strcat(lastname,firstname);
fprintf(database,lastname);//Write the stuff out.
fprintf(database,"\n");
printf("\n");
printf("Enter a Phone Number\n");
getaline(phone);
fprintf(database,phone);
fprintf(database,"\n");
fflush(database);
mainmenu();
}
void Casetwo()
{
fseek(database,SEEK_SET,0);//Move to start of file
int count=0;
do{
ourpos=ftell(database);
char test[100];
getalinefromafile(test);
ourpos2=ftell(database);
printf(test);
printf("\n");
}while(ourpos<ourpos2);
mainmenu();
}
void Casethree()
{
printf("The file is deleted\n");
fclose(database);
database=fopen(filename,"w");
fclose(database);
database=fopen(filename,"a+");
mainmenu();
}
void Casefour()
{
printf("Note:because c does not support _srcicmp all names that start with lower case letters are counted as less then any name that starts with uppercase\n");
char buff[100];
char test[100];
int i=0;
fseek(database,SEEK_SET,0);//Move to start of file
ourpos=ftell(database);  //These two lines are to discount the new line on the fisrt line of the database file.
getalinefromafile(test); //I don't want to stop making it, as i make the database file look better
int count=0;
do{
ourpos=ftell(database);
getalinefromafile(test);
ourpos2=ftell(database);
if(i==0)
{
strcpy(buff,test);
strcat(buff,"\n");
i=1;
}
else
{
strcat(buff,test);
i=0;
strcpy(orderit[count].holder,buff);
filelist[count]=orderit[count].holder;
count++;
}
}while(ourpos<ourpos2);
int k=count;
qsort(filelist,count, sizeof(char*), compare);
i=0;
fclose(database);
database=fopen(filename,"w");
do{
fprintf(database,filelist[i]);
i++;
fprintf(database,"\n");
}while(i<k);
fclose(database);
database=fopen(filename,"a+");
mainmenu();
}
void mainmenu()
{
printf("1.Add Data\n2.View File\n3.Erase File\n4.Order the file\n5.Quit\n");
getaline(switchint);
int switchjunk=atoi(switchint);//this is to show you how to use atoi. I don't really need to use it
switch(switchjunk)
{
case 1:
{
Caseone();
break;
}
case 2:
{
Casetwo();
break;
}
case 3:
{
Casethree();
break;
}
case 4:
{
Casefour();
break;
}
case 5:
{
printf("Quiting");
break;
}
default:
{
printf("Thats not a option brainless\n");
mainmenu();
break;
}
}
}

int main(int argc, char** argv){   //This program does not do dynamic memory.I don't want to use the C io AND track down NULL pointers :-).
printf("Please Load the database file\n");
getaline(filename);
database=fopen(filename,"a+");
mainmenu();
return EXIT_SUCCESS;
}
0
 
darinwCommented:
I'd appreciate it if you would post the answer here too.

darinw
Customer Service
0
 
djtanseyAuthor Commented:
why is that darinw? (if i may ask...)

djtansey
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
djtanseyAuthor Commented:
oops... wrong browser window :)
0
 
djtanseyAuthor Commented:
why is that darwinw?
(if i may ask...)


djtansey
0
 
darinwCommented:
Because all answered questions become part of the Previously Asked Questions area (PAQ). Others who may have the same or similar problems can search through the PAQ and find your answered question only to find out the answer was 'Thanks for the email - it worked' as the answer.

It happens sometimes and I have to deal with the customer who feels ripped off (and rightly so I might add) because they paid points to see that an email exchange took place.

darinw
Customer Service
0
 
djtanseyAuthor Commented:
sounds good enough to me, thanks, i will make sure i always post the answers..

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.