Solved

For laeuchli only...

Posted on 2000-02-27
7
281 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
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

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

darinw
Customer Service
0
 

Author Comment

by:djtansey
Comment Utility
why is that darinw? (if i may ask...)

djtansey
0
 

Author Comment

by:djtansey
Comment Utility
oops... wrong browser window :)
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:djtansey
Comment Utility
why is that darwinw?
(if i may ask...)


djtansey
0
 
LVL 3

Expert Comment

by:darinw
Comment Utility
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
Comment Utility
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
Comment Utility
/***************************************************************************
                          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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now