Solved

For laeuchli only...

Posted on 2000-02-27
7
287 Views
Last Modified: 2010-04-20
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
0
Comment
Question by:djtansey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:darinw
ID: 2566848
I'd appreciate it if you would post the answer here too.

darinw
Customer Service
0
 

Author Comment

by:djtansey
ID: 2570252
why is that darinw? (if i may ask...)

djtansey
0
 

Author Comment

by:djtansey
ID: 2570253
oops... wrong browser window :)
0
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

Author Comment

by:djtansey
ID: 2570254
why is that darwinw?
(if i may ask...)


djtansey
0
 
LVL 3

Expert Comment

by:darinw
ID: 2570501
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
 

Author Comment

by:djtansey
ID: 2570871
sounds good enough to me, thanks, i will make sure i always post the answers..

0
 
LVL 5

Accepted Solution

by:
laeuchli earned 820 total points
ID: 2570964
/***************************************************************************
                          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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question