jephthah 1,888 Posting Maven

EDIT: retracted


.

jephthah 1,888 Posting Maven

when you call " DS1302GetAll (&systime); ", as Narue said, that function will fill all the elements of the "systime" structure with the individual time and date components.

then, in order to push this info to the LCD in a human-readable way, you need to format the elements in an organized, meaningful manner that the LCD output code understands it. that's what youre doing when you call the " sprintf(buf ... " call; it formats this time & date info into the string "buf", so that your subsequent call to " lcd_puts() " knows what to do.

one thing i'm uncertain about here, is your "printf()" command... you're programming a microcontroller, right? where exactly is this "printf()" command supposed to print it to? you shouldn't have a terminal. your output device is the LCD, and you've already sent the info to the LCD via the "lcd_puts()" function.


.

jephthah 1,888 Posting Maven

yeah, she is.

she's even a jerk to other jerks.

jephthah 1,888 Posting Maven

i'm confused.

are you taking a class in C++?

or C?

jephthah 1,888 Posting Maven

this is C++ code.

you'll have more luck getting help in the C++ forum

jephthah 1,888 Posting Maven

for some reason, im really tempted to PM you ins Deutsche.

jephthah 1,888 Posting Maven

^ that would take the fun out of it.

jephthah 1,888 Posting Maven

Dear Sir, I find your capability to handle the situation to be entirely insufficient and I have therefore taken proactive measures to rectify matters to my personal tastes, exercised posthaste and with extreme prejudice. Best Regards.

jephthah 1,888 Posting Maven

I'm partial to the use of "strftime()"

#include <time.h>
#include <stdio.h>
#include <string.h>

void timestamp_string (char * myString)
{
    char     timestamp[16];
    time_t    caltime;
    struct tm * broketime;

    // find current time, convert to broken-down time
    time(&caltime);
    broketime = localtime(&caltime);

    // append timestamp in the format "_yymmdd_hhmmss"
    strftime(timestamp,16,"_%y%m%d_%H%M%S",broketime);
    strcat(myString,timestamp);

    return;
}

int main()
{
    char name[128];
    int i;
    
    printf("\nenter string: ");
    
    fgets(name,100,stdin);  // get string, strip newline
    do { 
        if (name[i]==0x0D || name[i]==0x0A)
        {
            name[i] = 0;
            break;
        }
    } while(name[++i] != 0x00);
    
    timestamp_string(name);
    printf("timestamped : %s\n", name);
    
    return 0;
}
jephthah 1,888 Posting Maven

You people have no sense of humor.

iswydt. (at lesat i think so)

i've found that my favorite deadpan style of humor is very difficult to pull off in a text medium.

:P

jephthah 1,888 Posting Maven

all of those three things can quite easily be coded into the message of a single packet.

jephthah 1,888 Posting Maven

WHAT are you going on about? we're not talking about Microsoft's Windows Server OS, he's using the "C Language" to program a "microcontroller". perhaps you've heard of these things?

nine posts, and all you've done is add confusion and nonsense. if you cant contribute anything remotely relevant, just go on an' git.

jephthah 1,888 Posting Maven

^ you havent heard of Unix? or his schools' particular implementation? :P most unix systems are named. it's just a geek thing. his school's is named Frodo. Mine was named Eos. ive seen others such as "Dante" or even more recently, "Quidditch". i figured that was what he was talking about, but it's not particularly useful to refer it to people who dont go to your school.


^^ anyhow, JimD, those variables you refer to are defined in the header files such as /sys/socket.h, /arpa/inet.h ... if your program cant find those #defines, then maybe those libraries are not being made available to you on your system, or they're in an unusual location.

IIRC, my undergrad program did not allow people to set up servers on the campus unix system.

so, if you're having trouble, i'm not surprised. i doubt you'd be able to set up a server/client even within your unix network, and i'm certain you won't be able to do it remotely.

try using it on your home computer instead.

you can run the server and client on the same machine, and use the localhost IP. But a more interesting example would be if you have two machines (say a laptop and a desktop) networked through a home router.

jephthah 1,888 Posting Maven

i dont think anyone knows what your schools frodo is.

simple answer: run sockets on Unix/Linux using teh <sockets.h> library.

run socket programs on windows using the <winsock.h> library.

the rest is just details.

jephthah 1,888 Posting Maven

It is not clear to me why you

shush. grownups are talking, now.

WaltP commented: Don't be a jerk -3
Narue commented: Indeed, you're becoming more and more obnoxious these days. -7
jephthah 1,888 Posting Maven

I believe the problem is that the OP is trying to test for logical equivalence on two strings of characters, but since they are actually pointers, their contents can not be compared directly.

jephthah 1,888 Posting Maven

i think we'll wind up being a mystery to whatever comes afterwards, like the dinosaurs are to us.

jephthah 1,888 Posting Maven

WUT? :confused:

gotdam theres a lot of misinformation being thrown around in this thread

i wish some of you people would go take a biology class or something

it's kind of embarrassing.

jephthah 1,888 Posting Maven

conservatives are funny. it's amazing how they can so completely jettison every fundamental, foundational tenet of their political ideology, then turn around and say its the fault of the liberal media or some such when their bacchanalian orgy of cut-and-spend fiscal policy blows up in their face.

liberals on the other hand are kind of a sad case. even when they get all power they still act like they dont know WTF to do with it, and destroy any chance of organization by accepting every fruity idea that comes across the plate in the name of 'tolerance', while arguing themselves in circle over the most trivial matters.

in short, conservatives are more exciting. give them power and they'll go and blow a bunch of stuff up, destroy a few nations, wreck the economy, and shift the blame to someone else when no one's looking.

whereas liberals just sit around navel gazing themselves into a state of stupefied paralysis.

jephthah 1,888 Posting Maven

#
/* ... omitting irrelevant, working code here ... */
#

well, gonna be hard to tell whats going on, because that code is definitely not irrelevant, and i can't be sure if it's necessarily working.

specifically, i dont see what 'r' and 'c' are pointing to. is the memory being allocated? for all i know they could be uninitialized pointers. and what is 'verbose'?

jephthah 1,888 Posting Maven

Off late many IT companies in my country have started treating employess like a slaves , work 16-20 hours a day , seven days per week , since there are not many jobs in the it market , looks like we need to publish top ten dirty it companies list soon.

that sounds pretty bad. what country do you work in?

im surprised, because programming type jobs really suffers from diminishing returns -- even negative returns -- when people are overworked and subject to being sleep deprived.

you wind up making more mistakes that costs time and money to go back and correct

jephthah 1,888 Posting Maven

Man ... was a Hunter before he settled down

hunter-gatherer.

humans are "omnivores"

as much as some people like to think they are carnivores, they are not.

jephthah 1,888 Posting Maven

standard ascii chars as you know them run from decimal values 0-127... the alpha, numerics, and traditional symbols.

extended ascii codes run from decimal values 128-255, and include all sorts of icons and squiggly bits... problem is they can differ from platform to platform.

do a search for "extended ascii codes"

jephthah 1,888 Posting Maven

this will end well.

:|

jephthah 1,888 Posting Maven

there is no "normal ansi C" that standardizes the bazillion different possible terminals into one set of interfaces.

termios is the closest you'll get and even it has issues.

sounds like you'll need to dig down into your assembly code and roll your own interrupts.

jephthah 1,888 Posting Maven

your "i" and "j" are uninitialized indexes to a finite array.

when you start the program, they're probably eleventysevenbillion.

whereas you probably want them to be zero

:P

jephthah 1,888 Posting Maven

conio is a windows-only library thats nice when it works, but god help you if you ever have to port code that relies on it.

termios and/or ncurses is a posix solution that might be more likely to yield results on your niche application.

or maybe it wont. i dont know. you're outside standard C now, so who knows what will happen.

FWIW, you can start here

jephthah 1,888 Posting Maven

yeah. i wish i had less complaints about borland, and more solutions for you

:(

last bit of advice.... use your debug environment to step through your code one line at a time, and watch the variables in question.

thats really the only way to fix this.

jephthah 1,888 Posting Maven

so I shouldn't use fgets?

No, you should definitely use fgets.

i just meant it changed things for my understanding of how you were writing your data to the file.

do continue to use the "binary" mode for reading and writing you will need that.

but i tried to run this in my debugging environment in order to inspect how the delete was working, and it just pretty much crapped the bed.


it's not your fault. youre being forced to work on a platform that no one else in developed nations uses. Borland is a scam, in my opinion, they sell their crap really cheap, dirt cheap, to schools in places like your country and India and others, and get people working on all this non-standard crap.

then you just have to unlearn it if you ever want to work anywhere that's not a local extension of your college, and you're pretty much prevented from collaborating with anyone that works in the standardized industries.

Borland sucks.

I'm sorry you have to deal with it.

.

jephthah 1,888 Posting Maven

gah.

i tried to open in a different debugging environment, now it's barfing on me because you're using all those scanfs expecting a pointer to char, but writing to structure aggregate.

not to mention your highly non-canonical use of "getch" . all these non-standard C causing undefined behavior is killing me.

man, i'm sorry, i thought i could just strip the borland terminal graphics stuff out, but just theres too much work here to undo this to be even remotely portable.

and i've got to go home now, and i know this wont fly on my linux machine.


good luck

jephthah 1,888 Posting Maven

o wait.... i see what you're trying to do...

you're trying to write the binary values of the structure itself to a file.

i just assumed you were writing the strings themselves.

hmm. kind of changes things.

jephthah 1,888 Posting Maven

"Only the True Messiah denies the nature of his divinity"

jephthah 1,888 Posting Maven

here's an example of fgets(). fgets has two important distinctions. it allows you to choose the stream (stdin or file), and requires you to indicate how many characters will be accepted. gets will not check and will cause the entire program to crash if user enters too many.

ive combined it with sscanf() which is different than scanf because it scans a string, and is more easy to control, IMO.

char menu_str[3]; // what the user enters (can be anything)
   int menu_valid;  // is the user entry valid?
   int menu_option; //  user selection converted to decimal    
   FILE *cPtr, *crPtr; // pointer to ajcustomer and ajservice files

   // ...

   menu_valid = 0;  // assume invalid until proven otherwise
   while (!menu_valid)
   {
      fgets(menu_str,2,stdin);//accepts two chars for user's option
      menu_valid = sscanf(menu_str,"%u",&menu_option); // look for unsigned decimal
   }

   // menu_str has been converted to integer
   if(menu_option != 0)
   {

      switch(menu_option)
//...

one thing... dont take the criticism personally. everyone here was a beginner once and we all made the same exact mistakes.

i also want to say that that i'm impressed by the artistic skill and detail you've put into this. it's quite impressive -- even though i despise Borland's nonstandard C code that gets you there.

it's good stuff. because you can get a job developing user interfaces. i know a guy at microsoft who that's all he does, and hes quite successful.

(still, do remember that a broken program, no matter how pretty, is still broken.)

jephthah 1,888 Posting Maven

do NOT use "gets" ... use "fgets" ... using "gets" is probably the single worst programmatical error you could ever make. that command should be cut out of the C Language like a malignant tumor. Truly, it's even worse than "fflush(stdin)"

and look. i quite think your instructor WILL expect your text file that contains your customer data to be accurate.

(1) if its not accurate, you've lost data. In the "real world" that's MUCH WORSE than not having a program work at all.

(2) how can you delete information if the information is mangled and written in a semi-random manner? you can't even know where the information is in order to delete it.

your delete function is not working partially becasue your add function is not working. for one thing youre not even writing the customer ID to your file. How can you find the customer record if you're not even writing the ID?

one solution to that problem is to make the customer ID a string, not an integer.

another major problem with your delete function is that the "blank record" or whatever you call it that youre trying to use to overwrite the customer record you want to delete... it's all just empty strings. as in "zero length" empty strings.

you need to write strings of NULL characters (0x00) of a length equal to the fields youre trying to wipe out.... or write blank spaces, if your program does not …

jephthah 1,888 Posting Maven

you can take my bacon from me when you pry it from my cold, dead fingers.


mmmmm..... hog fat. [/homer]


.

jephthah 1,888 Posting Maven

i would, but i have to go wash my dog.

Salem commented: LOL +0
jephthah 1,888 Posting Maven

lets see what we got here:


someone who was voted "most likely to become a serial killer" by his own classmates

... goes and broadcasts this tidbit on a casual chat web forum

... and then shows no ability to take a joke related to it.

ummm, yeahhhhh .... i want to party with that dude.

:|

.

jephthah 1,888 Posting Maven

Is that you, John Wayne?

jephthah 1,888 Posting Maven

ha.

but unfortunately, language gender has about zero correlation to anything remotely related to physiological gender, even stereotypical traits.

i wish it did, it sure as hell would make learning a foreign language easier for me.

jephthah 1,888 Posting Maven

yeah, that's nice and all, but i think this is just a CSC 101 assignment to learn how to sort strings alphabetically.

i mean your 400-level solution is impressive, but i doubt fast tree algorithms is what a 100-level beginning student needs, when they're still struggling with loops and arrays.

:P


.

jephthah 1,888 Posting Maven

i keep seeing your screen name, and thinking it says: Mr Daniweb


i figure I'm either kind of dyslexic, or I'm onto something big....

:S

jephthah 1,888 Posting Maven

here's a simple algorithm you can try.

1) read your values into an array. lets say you have ten values, randomly located in array[0] - array[9]
2) decide which end will be lowest value, which will be highest. say array[0] will be low, and array[9] will be high.
3) start with the element in array[0] and compare it to each of the others, 1 - 9
4) if one of the elements is smaller than array[0], swap them. compare each of the remaining elements in turn. once you're done comparing to all nine other elements, array[0] will be the lowest value.
5) next look at array[1] and do the same thing, comparing against elements 2 - 9, swapping if its value is smaller. leave array[0] alone since it's already the smallest. once youre done, array[1] will then have the second-smallest value.
6) then go and get array[2] and compare it to each of the remaining elements, 3 - 9, leaving elements in array[0] and array[1] alone.
7) ....
8) and so on until you're done.

you'll need a nested loop to accomplish this. an example, but not necessarily a completely accurate example, is like such:.

for (j = 0; j < NUMBER_OF_SAMPLES; j++) 
{
    for (k = j; k < NUMBER_OF_SAMPLES; k++)
    {
        // do that voodoo that you do
        // ...
        // ...
    }
}

some questions for you to consider:

(1) how will you read all of …

jephthah 1,888 Posting Maven

^ WTF did you just say?

:confused:

jephthah 1,888 Posting Maven

first off, the very first thing i've found is that your "add customer" function, which you said is working, is in fact not working.

i entered sample data for two of examples, and the resulting text as stored in the "ajcustomer.dat" is completely mangled and missing more than half of the information.

part of this problem is your use of, for example, scanf("%s", &customer.address_line1); does not allow spaces in the code.

so if my address is entered as "22 Acacia Avenue", it loses everything but the "22"

inspect your "ajcustomer.dat" and you will see what i mean.

you really need to have the precise format of this data file specified before you begin, and make absoultely certain that all of your fixed-width fields are indeed being entered exactly as you think they are supposed to be.

i strongly suggest that you get rid of all instances of "scanf()" and replace them with "fgets()" to read from STDIN

another thing you dont need to do is open the file as a binary file. this is a text file, just open it normally.

jephthah 1,888 Posting Maven

I've got to hand it to you, your styling is very nice, and obvious you spent a lot to make it look sharp with the colors and terminal graphics..

but to be honest, you really ought to consider the time it takes to do all of that, when you have problems getting your code to work.

basically: get it to work first. THEN add the eye candy.

for one thing, its damn near impossible for anyone to help you with all the extra stuff confusing the matter.

so now here is your code, with all the Borland crap stripped out. maybe we can work on figuring out what the problem is....

#include <stdio.h>//standard input/ouput header

void menu(void);//Function Prototype for user menu
void loading(void);//Function Prototype for loading function
void add_customer(FILE *cfPtr);//Function Prototype to add new customer record(s)                                                
void delete_customer(FILE *cfPtr);//Function Prototype to delete customer record(s)
void edit_customer(FILE *cfPtr);//Function Prototype to edit customer record(s)
void view_customer(FILE *cfPtr);//Function Prototype to view customer record(s)
void add_service(FILE *crptr);//Function Prototype to add ner service record(s)
void delete_service(FILE *crptr);//Function Prototype to delete service record(s)
void edit_service(FILE *crptr);//Function Prototype to edit service record(s)
void view_service(FILE *crptr);//Function Prototype to view service record(s)

union service_type
{
   char service1[10], service2[10], service3[10], service4[10];
   char service5[10];
};

struct customer
{
   char fname[12], lname[12], dob[10], land_line[8], cell_phone[8];
   char address_line1[50], address_line2[15], email[35];
   union service_type serv_type;
   int c_id;
   float total;
};

typedef struct customer CUSTOMER;//new alias for customer structure

struct service
{
   int s_id;
   char customer_name[35];
   char s_type[35];
   float cost;
};
jephthah 1,888 Posting Maven

oh dear. i really do think Borland is exploiting the schools in countries like Jamaica and India.

no one of any credibility uses Borland here in the States, that I'm aware of. Borland used to be a leading software company in the 80s and early 90s, but now they've turned into essentially a really bad joke. it's quite sad.

And I'm no microsoft fan eitehr, to be sure. any of the GCC deriviatives are based on industry standards, and are completely FREE.

but i digress.

i apologize for getting your hopes up, but theres no way i can get your code to work over here at this point. i have to rip everything out, and rewrite half of it.

some days i think about putting borland on just so i can try and help some of you folks out there, but it's a huge PITA, and i dont want to screw up my work environment here at my job. and i dont even use windows at home, so theres just nothing much i can do.

maybe someone else has borland?

otherwise, read my suggestions and see what you can do.

did you consider my "easy solution" to rewrite the file after each modification? is that even an option for you or are you required to modify the text on-the-fly?

jephthah 1,888 Posting Maven

your terminal graphics, from what i can tell, are VERY nice.

unfortunately, i cant get any of it to compile.

one question: where are you that your instructor requires Borland?

jephthah 1,888 Posting Maven

this is going to be difficult for me, becuase your code is full platform-specific terminal colors, and calls to a "cprintf()" function that is deprecated even in MSFT's crapyy <conio.h> library. I'm going to have to remove all of that stuff just to get the code to compile.

you really should consider getting rid of all this obscure coding practice that is specific to old microsoft platforms. your code just wont work on a probably 50% of the machines in use today.

another major problem is your widespread use of fflush(STDIN). that is a huge mistake never do that. get rid of those statements, and cuss out whoever told you that is acceptable program development practice.

jephthah 1,888 Posting Maven

theres no way i can help very much with your code.

one problem here is i dont have enough information to try and test your code.

but, I'll go ahead and try and explain how you should approach this problem...


EXECUTIVE SUMMARY: All of this totally depends on how your text file is organized if your text file is organized logically and in clearly fixed patterns, it will make your job a lot easier.

IF each record in your file is a fixed size (meaning each record has the same number of fields, and each field is the same width), THEN you can relatively painlessly use fseek() and/or rewind() to modify text within a file.

BUT if your records and/or fields vary in number and size, then you're going to have a helluva time.

"The Easy Option" -- which may not be one that your instructor will accept -- is to read the entire contents of your data file into memory organized into arrays and/or structures, then modify the memory contents, then rewrite the contents into a new file (ie, overwriting the original)

is that an option for you? i dont particularly like it, because it's not a very scalable solution. but it might be an option to turn in a program at the last minute that "works"

otherwise, you'll have to do it like this:

to add a record, merely open a file to append and the additional info …

jephthah 1,888 Posting Maven

awww. crap man, i didn't even notice his "void main"... i just edited his original code for the relevant parts where he was passing the array.

thats not fair.

:(