yellowSnow 607 Posting Whiz in Training

Hello every one.I coded a program to print current date and time.
First I declare a function tim() to calculate the current time.
It works well.But the problem is I cant call the function from main() function.It doesnt print any thing.What is wrong with this code?
Please help me.Thanks very much!
here is my code.

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

char* tim()
{
struct tm *d;
time_t now;
char li[50];
char* temp;

    time(&now);
    d=localtime(&now);
    memset(li,'\0',sizeof(li));
    strftime(li,50,"%Y.%m.%d.%H.%M.%S",d);
    temp =li;
//  printf("time now:%s\n",temp);   
    return temp;

}

int main()
{
char* array;
array=tim();
printf("Time:%s\n",array);

}

end quote.

Again - within the space of 24 hours you ignore advice about formatting your code correctly, You are extremely lucky there are good folks on this forum who are still prepared to help you.

Since you missed it the last time - READ THIS POST:
http://www.daniweb.com/forums/thread93280.html

yellowSnow 607 Posting Whiz in Training

If I change your ViewStudRec() function to this:

void ViewStudRec() {
    int ctr, ctr2;
    int space;
    system("cls");
    printf("\n-----View Student Records-----\n\n");
    printf("Student Code");
    printf("\tLast Name");
    printf("\tFirst Name");
    printf("\tMiddle Name");
    printf("\n");
    for (ctr = 0; ctr < StudRec_count; ctr++) {
        printf("%s", StudRec[ctr].stud_num);
        printf("\t%s", StudRec[ctr].stud_lastnam);
        printf("\t%s", StudRec[ctr].stud_firstnam);
        printf("\t%s", StudRec[ctr].stud_midnam);
//        strlen(StudRec[ctr].stud_midnam);
//        space = (16 - strlen(StudRec[ctr].stud_midnam));
//        for (ctr2 = 0; ctr2 < space + 1; ctr2++) {
//            printf(" ");
//        }
        printf("\n");
    }
    system("pause");
}

This is the output I get:

-----View Student Records-----

Student Code	Last Name	First Name	Middle Name
2009-1234	Asa	Gohan	Gog
2009-4321	Basha	Bushum	Jujo
2009-1999	Mekemi	Mekeke	Makek
Press any key to continue . . .

I'm not sure why you keep on insisting using that inner for loop for printing out spaces - when you reach the end of the line, just print a new line character.

As for your strange output - well I'm not sure. Obviously you're accessing other areas of memory within your program. If you know how to use a debugger, then I would try stepping through this function and watch the values of your fields before they're output.

yellowSnow 607 Posting Whiz in Training

You have obviously paid no attention to any advice given to you. You have not formatted your code and ignored advice on how to fix your code provided by Dave Sinkula and me.

Well good luck buddy!

yellowSnow 607 Posting Whiz in Training

Use a forward slash; #include necessary headers.

OK. While we're at it - other things to consider:

1) you are not returning a value - main() returns an int.

2) your strdup() and sprintf() function calls are all wrong. Have you studied how these functions work? With strdup(), you are trying to assign the return string to a character!

3) sprintf() parameters are wrong. This function is similar to printf() except that the output is stored in the character array. I'm not sure why you even want to do this considering that you've called strdup() in the previous line. It's either one or the other.

4) I think your logic is a "bit off". It seems like you want to read a line from your file and assign each line to an element of your array - an array of strings. If this is the case, then your declaration for c needs to be an array of pointer to char - char *c[128]. And then you'll have to allocate memory for each pointer as well before pointing it anywhere.

yellowSnow 607 Posting Whiz in Training

In your haste to post your poorly formatted code, you may have missed the opportunity to read the sticky notes at the top of the forum page. In particular, how to ask questions properly and how to format code using code tags.

Read these notes and try again.
http://www.daniweb.com/forums/thread78060.html
http://www.daniweb.com/forums/thread93280.html

yellowSnow 607 Posting Whiz in Training

How about writing a test program to test your assertions?

yellowSnow 607 Posting Whiz in Training

Change this line:

saveToFile(*client_file, &client);

to this:

saveToFile(client_file, &client);

In addition to this, you should also check that the call to fopen() is successful - Salem gave you the code for this check in post #8.
Good luck!

yellowSnow 607 Posting Whiz in Training

Hi thanks so much for the other corrections.

And.. about the problem, I have been saving my file as filename.cvs.txt all along.

So I reverted it to the .cvs extension and there's nothing wrong with the reading.

Please declare this thread as solved, but I may post another problem regarding the same program.

Posted in error - the code in this thread is very similar to the code in another thread (by the same OP) that I was posting to!

yellowSnow 607 Posting Whiz in Training

Are you talking about calling Java from C? If so, you'll have to make use of the JNI. I've only done it the other way round - Java calling C through the JNI.

Perhaps this article may be useful (it's not for the faint-hearted):
http://java.sys-con.com/node/45840

yellowSnow 607 Posting Whiz in Training

It's no point posting ~500 lines of code and then asking someone to "fix" your code. Make an attempt to post the smallest amount of code that isolates your problem. You never know, by trying to do this you may actually work out what the problem is for yourself.

A few things to fix:

1) Don't use fflush(stdin) - it's WRONG!

2) Make up your mind what name you want for your file - is it students.cvs or students.csv - you use both names in your program.

3) Use the function fgets() in place of gets()

4) You're using "magic" numbers e.g. 58, 126

5) As far as your ViewStudRec() function is concerned - get rid of the inner for loop that prints spaces (you're already at the end of the line) and just print a newline character. After you fix that, you just need to change your code so your data is aligned directly under your column headings.

yellowSnow 607 Posting Whiz in Training

Help is given to those who help themselves by showing some effort. Perhaps you should post some code.

yellowSnow 607 Posting Whiz in Training

Erm, such like syntax error that kind, got what other type of error else?

What on earth are you talking about?
Follow the rules of the forum and ask a proper question.

yellowSnow 607 Posting Whiz in Training

Thank you very much for the prompt reply. It does store the element "putval[0]" in "b[0]", but how should i approach, if I want to return the whole "pulval" array into "b"

I'm not sure what you're trying to do - seems awfully convoluted for a "long to hex" conversion. So at this juncture, I'll just add to Ancient Dragon's list of issues you have:

1) Never ever ever ever use void main(). At the very least declare the main function as:
int main() or
int main(void).

2) You should include the string.h header file for the strlen() function.

3) Your long2hex function is returning the address of a local variable - this is going to give you grief.

And as AD mentioned in his post, why do you want to return an array of 5 pointers?

yellowSnow 607 Posting Whiz in Training

And your question is? Please refer to this link:

http://www.daniweb.com/forums/announcement118-2.html
While you're at it, as a "newbie", you should read all the sticky posts at the top of the C forum page.

yellowSnow 607 Posting Whiz in Training

the user will enter his/her month and day of birth and the program should display the corresponding zodiac sign and the character and personality of the person having that kind of zodiac

The problem with your code is that your case labels are wrong. Case labels must be some form of integer constant - you're labels are strings. I suggest that you do a little research and learn how to use switch/case correctly.

Other issues:

1) void main() is WRONG! Use any one of the following for the signature of the main function:
- int main()
- int main(void)
- int main(int argc, char *argv[])
- int main(int argc, char **argv)

2) Try to avoid the use of non-standard functions such as those associated with conio.h. If I was a betting man (and I am), I would bet that you're using Turbo C.

3) In future, when posting code, use code tags - this way your code will be formatted correctly and members of this forum are more likely to help you. Here's a link on how to use code tags - click it, read it and apply it.
http://www.daniweb.com/forums/thread93280.html

yellowSnow 607 Posting Whiz in Training

Do you want to actually post the code with regards as to what you want to do? It's blank!

yellowSnow 607 Posting Whiz in Training

yellowSnow -
I am not IGNORING your advice. I simply do not understand it all, or want to try something on my own.
I do not want free code handed out to me. I never asked for it, and I told you that. I also thanked your for your time, and I appreciate the effort you gave on the problem, but you you also continually ignore what I am asking and simply give me code.
I ask for help in understanding, NOT free fixes to problems that I did not write. Your code was great, but I did not write it, and I do not want credit for it.
I am working on trying to understand problems and come up with my own fixes to things. I am never going to learn anything if I just take your code and put it in a program.
I know my fixes are not as smooth as yours, but I have been coding for 4 weeks now, I do not think they would be. If I just take your code, put it in my program and move on I am never going to learn anything.
I am sorry this seems to aggravate you.

It's very admirable that you want to try something on your own - unlike some others on this forum. And for the record - it does not aggravate me - it does disappoint me a little.

But please look back at your previous …

yellowSnow 607 Posting Whiz in Training

Hello, yes it's me again.

I cannot believe you. I gave you a full blown working version of what you're looking for and you still keep on insisting on posting versions of the code that don't work. I spent a great deal of time in your PM response (which you should never have sent to me), but you just happily say "it doesn't work" and keep posting.

I not only "fixed" the basic validation issues you were having, I re-factored your code and made it far more readable. You ignored my advice about moving the validation code out of main() and into the functions that are responsible for that data and you have totally ignored the additional function that takes a whole lotta crapola out of your main().

Based on one of the last posts to your thread:
http://www.daniweb.com/forums/thread212611.html

you again have ignored my advice to RUN MY CODE - you just keep going back to the original versions of your code that you originally had problems with and then keep posting that it doesn't work.

The previous posts in this thread do make a good point though. Turbo C is not good - but Miracle C actually makes TC look half decent (though it ain't).

yellowSnow 607 Posting Whiz in Training
return 0;

statement is a type of statement which is written at the last of any function which has its return type as integer(commonly).This is like a command saying "NOTHING TO DO" at the last of the functions definition.

What? Listen, I already answered the OP's original question and your answer is plain wrong. The return keyword in C means that the function is returning a meaningful value back to the caller of that function (in well written functions).

Saying something like "it's a command saying "NOTHING TO DO" is WRONG!!! Have you ever checked the return value of the fopen() function and what it potentially means? If you assumed that the return value of this function means "nothing to do", then you may be in for a rude shock.

It's been a month since I began participating in this forum and I cannot believe some of the misnomers that are put forward.

Sheesh!!!

yellowSnow 607 Posting Whiz in Training

Can you tell me the difference between the sky and the earth...!!!..??
your question and my question are similar...,..They have no relation to differentiate them..

the sky is what holds the snow and water and also the hanging place for the big light mean while the earth is the gruond on which we will walk and do all other
things .

I think the both of you should seriously consider your motives for "attempting" to even participate in this forum. Stop wasting the valuable time of members who treat this forum with decorum and respect.

yellowSnow 607 Posting Whiz in Training

Please can anybody tell me the difference in return 0 and system ("pause");

return 0 means the value 0 (usually some type of int) is returned from a function to the caller of the function.

system() is a library function that makes calls to OS commands/programs. system("pause") calls the "pause" command in DOS/Windows. Run the pause command in a command shell to see what it does.

yellowSnow 607 Posting Whiz in Training

I have not taught of it yet but i know i have to use gui.
After i have know what to do i will then figure it out.
Please help me.

You are "sort of a new programmer" and you want to start out programming GUIs. How about learning some of the core fundamentals of the C language first. There is plenty of information on the Web. If you took the time to look at the top of the forum page, you would have come across a thread called "Starting C". Have a look through this thread - there are plenty of links there to information on the C language - e.g. tutorials, references, FAQs, e-books etc. Ah .. what the hell - here's the link:

http://www.daniweb.com/forums/thread50370.html

This forum is for members to post questions on specific issues or aspects of the language - it is not a place to learn C "from scratch".

yellowSnow 607 Posting Whiz in Training

You're sort of close. I'm not absolutely clear of your exact requirements (with regards to what to do with word boundaries).

Look at the following code. I have hopefully simplified things for you a bit. Bear in mind that this program just outputs exactly "limit" characters per line (except perhaps for the last line) and does nothing "fancy" with word boundaries. So words will "break" across lines if the line size has been reached and consecutive words will be "butted" together if a newline character has been read before line size characters have been output.

Use it as a working template if you wish and modify it to your needs.

#include <stdio.h>
#include <stdlib.h>

void format_text(int lineSz);

int main(void) {

    int lineSz;     // line size

    printf("Enter the line length limit: ");
    scanf("%d", &lineSz);
    while(getchar() != '\n') {;}

    format_text(lineSz);
    return 0;
}

void format_text(int lineSz) {

    int ch;             // character from stdin
    int nChars = 0;     // chars per line counter
    FILE *outfile;

    if ((outfile = fopen("afile.txt", "w")) == NULL) {
        printf("Error opening file.");
        exit(EXIT_FAILURE);
    }

    printf("Enter the text in multiple lines terminated by ctrl-z on a separate line\n");

    while ((ch = getc(stdin)) != EOF) {

        // ignore newline characters and get next character
        if (ch == '\n') {
            continue;
        }

        nChars++;

        // output character to file if line size has not been reached
        // otherwise end current line and output current character
        // on next line
        if (nChars <= lineSz) {
            putc(ch, outfile);
        } else {
            putc('\n', …
yellowSnow 607 Posting Whiz in Training

Well ... if you have an idea on "how to do it" then post some code or at least a reasonably detailed plan on how you intend on approaching the solution.

Code talks ... everything else walks.

yellowSnow 607 Posting Whiz in Training

yellowSnow:
I like that code. It is so close to what I was trying to do that I understand it, and once I get it doing exactly what I want and become refined enough to improve on it I will have the base from which to build.

One question, why do I have to hit so many times after input?
For example, I input sale amount 10.00 and <enter>,
my prompt goes to the next line, but nothing happens.
I hit <enter> one more time and it continues to menu.
I select 1 as my menu option and hit <enter>.
Prompt goes to the next line, but I have to hit <enter> again to get calculations.
I had this same issue before, and never worked it out.

Did you use an exact copy of the code I posted? When I run the code (in either my IDE or in the DOS command shell), this is what I get:

Enter Amount of Sale $ 100
Tax Calculation for Purchase

1. Del Mar
2. Encinitas
3. La Jolla


Please Select Number of Store for Which to Calculate: 1

Del Mar         Sale $100.00    Rate 7.25%      Tax $7.25       Total=  $107.25


        Would you like to calculate for another store? (y/n) y
Enter Amount of Sale $ 200
Tax Calculation for Purchase

1. Del Mar
2. Encinitas
3. La Jolla


Please Select Number of Store for Which to Calculate: 2

Encinitas       Sale $200.00    Rate 7.50%      Tax $15.00      Total= …
yellowSnow 607 Posting Whiz in Training

@firstPerson
Besides this being a C forum, I don't think it helps that much to post C++ code and then suggest to the OP that he/she should try to convert it to C based on the relative skill/experience level of the OP (no offense intended to the OP).

@no1zson
OK. I feel that you've really been trying to nut this problem out. It also appears that you have gone a tad backwards with your last code posting in relation to the discussions we've had on this thread. So at the risk of getting blasted by other forum members, please try the code below out. And please read my comments after the code!

#include <stdio.h>
#include <ctype.h>

//defines tax value for calculations
#define DelMar 7.25
#define Encinitas 7.5
#define LaJolla 7.75

char cAgain; //variable for Y/N questions

float get_sales_amount() {

    float fAmount;

    printf("Enter Amount of Sale $ ");

    while ((scanf("%f", &fAmount) != 1) || (fAmount <= 0.0)) {

        while (getchar() != '\n') {;}

        printf("SALE AMOUNT CANNOT BE LESS THAN $0.00.\n");
        printf("It must be a valid decimal value. Re-enter: $ ");
    }

    while (getchar() != '\n') {;}
    return fAmount;
}

int get_store_number() {

    int iSelection;

    printf("Tax Calculation for Purchase\n\n");
    printf("1. Del Mar \n2. Encinitas \n3. La Jolla\n");
    printf("\n\nPlease Select Number of Store for Which to Calculate: ");

    scanf("%d", &iSelection);
    while (getchar() != '\n') {;}

    while (iSelection < 1 || iSelection > 3) {
        printf("INVALID NUMBER ENTERED! Please enter 1,2 or 3: ");
        scanf("%d", &iSelection);
        while (getchar() != '\n') …
yellowSnow 607 Posting Whiz in Training

I have taken an exact copy of the code you posted and except for a missing '&' in your scanf statement for that blasted cValid variable, everything seems to "work as expected" - as far as I know.

Besides ignoring advice on how to improve your code from others besides me, it seems to work fine.

Perhaps you need to post a "blow by blow" run down of your output for us to get a better understanding of what you think is wrong.

yellowSnow 607 Posting Whiz in Training

Wow sorry, I really didn't mean to get anyone mad. :( Yes, I have compiled everyone's code. Here's what the output looked like on the modified version of yours:
tWeNtY fIrSt CeNtUrY bReAkDoWn - gReEn DaY
tHiS iS a TeSt Of StRiNgS
Did I get it wrong? If so, I'm sorry.

The output you've posted is incorrect for the corresponding code I posted. That's the output you get if you change wordoffset = -1 to wordoffset--. If you run my ORIGINAL code you'll get:

tWeNtY fIrSt cEnTuRy bReAkDoWn - gReEn dAy

The OP "complained" that the output from Ancient Dragon's first response included the count of spaces for the mod calculation. From that response I concluded that the OP wanted the first letter of each word in the string to be lowercase and up-low thereon until the next word came along. That's the reason I posted the code changes that I did (based on AD's original code).

As I said in my previous post, I now "know nothing" of what the OP really expects. Until the OP posts exactly what is expected in the ouput I'm classing this thread null and void.

yellowSnow 607 Posting Whiz in Training

Replace wordoffset = -1; with wordoffset--; . :P

What are you getting at with this response?

Rightly or wrongly, I did mean -1!!!

Did you actually take the time to copy, change and compile the OP's, AD's or my code before posting this response? I think not. Read what's going on in this thread before responding with smart ass one off code liners! ;)

yellowSnow 607 Posting Whiz in Training

So what have you learnt (or even attempted) in the past two weeks?
http://www.daniweb.com/forums/thread208111.html

Obviously not that much.

Here's an idea, drop that Turbo C crap and move on to decent compiler/IDE setup.

yellowSnow 607 Posting Whiz in Training

Thank you so much for you help!

The camel case isn't quite coming out right. I've tried to fiddle around with it to make it come out but I can't figure it out.

Right now it comes out as:
Camel case: tHiS iS a tEsT oF sTrInGs

I would like it to come out as:
Camel case: tHiS iS a TeSt Of StRiNgs

Well looking at your so called expected output - nothing makes sense. Do you want alternate lower-upper casing based on the position of the character in the string (including spaces) or do you want the first letter of each word to begin with a lowercase letter? If it's the former, you have wasted my time and AD's as well, as he provided you with a solution on his first response.

Going on the expected output in your last post - it makes no sense - it doesn't match any of the proposed outputs from the above two alternatives. What are you actually looking for? Your expected output makes NO SENSE unless you have an algorithm in mind that you haven't communicated appropriately in your thread.

yellowSnow 607 Posting Whiz in Training

So when the camelcase is printed, it counts the spaces as characters. How do i get it to ignore the whitespace?

Some minor tweaks to Ancient Dragon's code snippet should do it. You need to detect the start of a word and calculate the modulus based on the offset into the word - like so:

#include <stdio.h>
#include <ctype.h>

int main() {

    char str[] = "Twenty First Century Breakdown - Green Day";
    int i, wordoffset = 0;

    for (i = 0; str[i] != 0; ++i, ++wordoffset) {

        if (str[i] == ' ') {
            wordoffset = -1;
            continue;
        }

        if ((wordoffset % 2) == 0)
            str[i] = tolower(str[i]);
        else
            str[i] = toupper(str[i]);
    }

    printf("%s\n", str);
    return 0;
}

There are probably better ways of doing it - but that's the way my brain is wired this evening.;)

yellowSnow 607 Posting Whiz in Training

1. Do you say that my program is fine? If there is need of code changes in my program can you plz tell me the changes that need to be made to avoid unreadable character in file...

2. which is the better function to read the contents of the file and store them in structure if the file already exists? I mean fgets() or fread()???

3. I have another program, can u code it?
Create a struct named emp_details with the following fields
EMP_ID
ADDR1
ADDR2
PHONE
Read in the values from a file and store them in the above structure. Create a new structure with employee name, id and address details. Copy the values from structures created in question 3 and 4 to this new structure and print the result...

1. I said your program works OK for what you want to do. I already told you what you need to do if you don't want "unreadable" characters in your file. Read my previous posts again. I think you're getting too hung up on this "unreadable" characters - meh .. your problem.

2. fgets() or fread()? It really depends on what you need to do. Are you reading lines of text file delimited by CRLF or are you reading blocks of data?

3. Can I code it? Yes I can. Am I going to do it? Heck no - but members on this forum will help if you show some effort …

yellowSnow 607 Posting Whiz in Training

thanks a lot. it works now.
a follow-up doubt :- once i am done with the program, say if i do not return it back to the OS, will it cause a problem the next time i compile and re-run it??
would that memory allocated still be used by the previous run?

It shouldn't cause any problems. There is probably no need to free memory blocks at the end of a program - all memory should be returned to the system once the program terminates - I suppose it's just a habit of mine that I free any memory that I allocate in a program regardless.

yellowSnow 607 Posting Whiz in Training

You need to use the realloc() function to allocate additional storage and copy the contents from the previous allocation. You are calling malloc() in your loop which is clobbering memory.

You call malloc once and then call realloc whenever you need to allocate additional memory and retain the contents already allocated.

You should also be checking that calls to malloc (and realloc) are successful. If memory allocations are successful you should also be calling free to return it back to the OS when you're done with it.

yellowSnow 607 Posting Whiz in Training

In all honesty, I'm not sure what you're trying to achieve with the cValid variable in your scanf statements.

If you want basic (and I mean really basic) validation checking for your float variable using scanf, try this little code snippet out and see if you can incorporate something like it into your code (and read the warning after the code):

#include <stdio.h>

int main(void) {

    float f;
    char valid = 'N';

    printf("Enter a float value: ");
    while (valid == 'N') {
        if (scanf("%f", &f) == 1) {
            valid = 'Y';
        } else {
            // consume erroneous characters before prompting again
            while (getchar() != '\n') {;}
            printf("Enter a float value: ");
        }
    }

    printf("float is %.2f", f);
    return 0;
}

Warning: this is very basic validation with scanf. If you enter "AB12", it won't validate, however if you enter "12.34AB", it will validate as correct and set the float variable to 12.34. Please understand this and the misgivings of the scanf function. As I stated earlier, Dave Sinkula's advice is the way to go for more bulletproof validation. I have only provided you with this sample as you have stated that validation as suggested by Dave Sinkula is beyond your capabilities at this stage.

The line of code that "consumes" extra characters should be used elsewhere in your code where this issue exists - i.e. ignore my suggestion in an earlier post about scanning for the additional character in the scanf statements.

yellowSnow 607 Posting Whiz in Training

While I'm at it, you'll have to do the same thing with this code in your main

while (iStorenum < 1 || iStorenum > 3) //if store number is not 1, 2 or 3
        {
            printf("INVALID NUMBER ENTERED! Please enter 1,2 or 3: ");
            {
                scanf("%d", &iStorenum); //scans input at INVALID prompt
            }
        } // end while loop

Another reason why I'm not a great fan of scanf() most of the time.

Damn! Another brain malfunction. Sorry, I didn't read your original post correctly. The issue I was referring to was regarding the fact that your loop will terminate after one iteration after prompting for another calculation due to the '\n' not being consumed from the previous scanf.

Dave Sinkula's advice is the way to go for the issue you raised with this thread.

yellowSnow 607 Posting Whiz in Training

I gave you a clue to this issue in your thread titled "GOTO command -C". You need to "consume" the '\n' character left over from when scanning the store number. Read my post again in that thread.

In your iMenu() function, replace:

scanf("%d", &iSelection);

with this:

scanf("%d%c", &iSelection, &cAgain);

I'm just reusing your cAgain variable - you should probably use a more appropriately named variable for this purpose.

no1zson commented: patient guy. really here to help. +3
yellowSnow 607 Posting Whiz in Training

If you don't want the "unreadable" characters in your file, you will have to initialize the members of your structure prior to loading them with data and writing to your file.

At any rate, since you are writing "raw" ints to your file, these fields will still appear as "unreadable" characters when viewing the file. For example, an empid = 100001 will be stored in the file as hex A1 86 01 00 (for a 4 byte int).

If you want all fields to be readable within the file, then you would have to store them as "strings".

I really don't see what the problem is really, since when you read the records from the file, the fields will either be interpreted as strings and the int will be converted on output (e.g. via printf).

If you want to verify that your program is writing data correctly to the file, use a hex browser/editor to view the contents of the file.

Just my 2.5 cents worth. ;)

yellowSnow 607 Posting Whiz in Training

I don't understand what your problem is - what you're observing in your file is expected based on the program you have written.

Let's take a look at the structure:

struct employee {
    char name[25];
    char doj[25];
    int empid;
};

You have allowed 25 characters for the name and doj members and an int for empid (most likely 4 bytes). So if you enter "John" for the name member, the first 5 bytes (including the '\0') will contain 'J', 'o', 'h', 'n', '\0' and the rest of the 20 bytes will contain garbage which I suspect is what you're seeing as unreadable characters. The same will occur for the doj member.

If you don't want the "unreadable" characters in your file, you will have to initialize the members of your structure prior to loading them with data and writing to your file.

yellowSnow 607 Posting Whiz in Training

First of all some housekeeping:

1. In future, when posting code, please use code tags - see this link:
http://www.daniweb.com/forums/thread93280.html

2. void main() is bad - use either one of the following for the signature of main:
- int main()
- int main(void)
- int main(int argc, char *argv[])
- int main(int argc, char **argv)

Now on to your code. I compiled it and it worked OK. Your formatting of output could be improved and your use of scanf for input will give you grief if you decide to you use more than two words for a name - but other than that it worked for me.

When you say it doesn't write the input properly to the file, what exactly do you mean? In my test run, it produces a file with a size of 168 bytes = 56 bytes per record (not 54 - due to boundary alignment of the int)

yellowSnow 607 Posting Whiz in Training

Here are just some "tidy up" suggestions:

1. Your j (of type char) and ptr variables are never used.

2. Rather than declaring separate variables to store each character as you read the characters of the input string for each translation, just use one. The same goes for the variables used as array subscripts. You just need to reset the subscript to 0 before moving on to the next translation.

/*Changes user input to all upper case*/
    pos = 0;
    do {
        c = input[pos];
        c = toupper(c);
        input[pos] = c;
        pos++;
    } while (c);

    printf("Upper case: %s\n", input);

    /*Capitalizes first letter of each word*/
    pos = 0;
    do {
        c = input[pos];
        c = tolower(c);
        input[pos] = c;
        pos++;
    } while (c);

3. The gets() function is dangerous - use fgets() instead.

4. You can print your output for each translation using one printf statement:

printf("Upper case: %s\n", input);

Cheers,
JD

Ancient Dragon commented: very good suggestions :) +36
yellowSnow 607 Posting Whiz in Training

Damn! I did it again. I didn't realise the age of this thread. Sorry people.

It would be great if threads of a certain age could be locked so that numbskulls like me don't keep posting to them.

Salem commented: Yeah - if it's got a little "flame" icon and over 1000 views, it's almost certainly a fossil. Perhaps "bones" would be a better icon ;) +36
yellowSnow 607 Posting Whiz in Training

Rather than "eye balling" the two files and trying to detect the differences, use a file compare utility that is provided with your OS e.g. fc on Windows or diff on Linux/Unix.

DangerDev commented: good point +3
no1zson commented: super helpful +3
yellowSnow 607 Posting Whiz in Training

I forget the question already...hehe^^
Oups, sory...I always use sms language...
This is malaysian language, haha!!!

Rubbish! Since when is SMS Malaysian?

I'll give you a tip mate, no one likes a smart a**, especially when:

1) they post unformatted code (USE CODE TAGS!)
2) they whine for help
3) they use stupid titles for their threads - what exactly do you want me to "have a look at"?
4) they refuse to listen to advice given to them about how to post correctly i.e. ask a question and use proper English.

Quite frankly, until I see an improvement in your posting style, I personally will not even waste a second about even thinking about helping you out.

yellowSnow 607 Posting Whiz in Training

I downloaded TC3 and tried it out (ahh .. the not so good memories) and I get the "black screen" thing happening as well. For me I have to wait 10 to 15 seconds when switching from TC to any of my other running Windows applications. I get a delay of this order even when taking the DOS shell option from the File menu in TC.

Besides that it does some "funky" things to the fonts in DOS shell - switches into CGA/EGA mode - even a half blind sucker like me can read the screen from 10 feet away!

Write a little program that prints the size of your int type and if that ain't enough reason to drop TC and run to the hills ... :-/

If you want to use an IDE, then I would advise you to upgrade your setup to something more modern and compatible with Windows XP. Personally, I use two setups:

1. Codeblocks (version 8.0.2) with the MinGW compiler. Here's the link to the download page:
http://www.codeblocks.org/downloads

2. the CDT plugin for the Eclipse framework (with MinGW).

I've also used Dev-C++ Bloodshed in the past - it's not too bad, but I prefer the other setup options from above.

yellowSnow 607 Posting Whiz in Training

Oh sorry, major errors occur at line 89....

I would advise you to develop this program and get one function working first before moving onto the next function. Trying to write it all in one hit and then resolving all the errors is a laborious chore and an inefficient way of doing things.

From having a quick look at your code (sorry it's Saturday night) and I ain't gonna be looking at all that code, I've put forward some issues to be addressed:

1. The signature of main() is incorrect - at the very least make it int main(void).

2. Most of your functions return int, but I don't see a value being returned to the caller via the return statement.

3. At the end of some of those function you appear to be trying to call main() - you need to return <int-value> in these functions to get back to main() or any other caller function.

4. I see you are using gets function. Lose it - it is a dangerous function - use fgets instead.

5. fflush(stdin) is just plain wrong - drop it.

6. You reference the getch() function which is non-standard - and at any rate you haven't included the conio.h header file.

Well, that'll do for now. As I said earlier try to develop the program one "feature" at a time and get THAT right before moving on to the next function. This program has far more …

Dave Sinkula commented: I gotta give props for hitting the common noob stuff, since I haven't had the patience for that in a while. +24
yellowSnow 607 Posting Whiz in Training

You would use a do-while loop. Essentially you'll keep asking for user input in the body of the do loop while the user keeps answering 'y' or 'Y' for more calculations.

int main() //main loop
{

    do {

        float fSales = 0.00; // Sales value for calculations
        int iStorenum; //defines store for main loop, menu will not work without

        fSales = user_input(); //new week 4 loop for sales total
        while (fSales < 0.0) //new week 4 loop to validate sales amount
        {
            printf("SALE AMOUNT CANNOT BE LESS THAN $0.00. Re-Enter: $ ");
            {
                scanf("%f", &fSales); // scans new input for validity
            }

        } // ends while loop

        iStorenum = iMenu(); //displays menu created above

        while (iStorenum < 1 || iStorenum > 3) //if store number is not 1, 2 or 3
        {
            printf("INVALID NUMBER ENTERED! Please enter 1,2 or 3: ");
            {
                scanf("%d", &iStorenum); //scans input at INVALID prompt
            }
        } // end while loop

        if (iStorenum == 1)
            //Calculates and Displays Del Mar Store, Sales, Tax rate, and Tax
            printf(
                    "\nDel Mar \tSale $%.2f\tRate %.2f%%\tTax $%.2f%\tTotal= \t$%.2f\t\n\n",
                    fSales, DelMar, fSales * DelMar / 100, DelMar * fSales
                            / 100 + fSales);
        if (iStorenum == 2)
            //Calculates and Displays Encinitas Store, Sales, Tax rate, and Tax
            printf(
                    "\nEncinitas \tSale $%.2f\tRate %.2f%%\tTax $%.2f%\tTotal= \t$%.2f\t\n\n",
                    fSales, Encinitas, fSales * Encinitas / 100, Encinitas
                            * fSales / 100 + fSales);
        if (iStorenum == 3)
            //Calculates and Displays La Jolla Store, Sales, Tax rate, and Tax
            printf(
                    "\nLa Jolla \tSale $%.2f\tRate %.2f%%\tTax $%.2f%\tTotal= …
yellowSnow 607 Posting Whiz in Training

Since the OP seems to be happy (quote - "hehe") for someone to do his (or her) homework, all I'll say about your code is DO NOT USE void main().

And I'm sure the OP is 'rily' happy for you to do this.

The main function should be declared as:

- int main(), or
- int main(void), or
- int main(int argc, char *argv[]), or
- int main(int argc, char **argv)

Just shoot the void as the return type.

yellowSnow 607 Posting Whiz in Training

This suggestion intrigues me. Putting my main loop inside another loop. I am not sure I understand how to do it, and it sounds almost more complicated than the problems it might potentially avoid, but if anyone can expand on this thought I would appreciate it.
Again, my limited experience hinders my understanding at this point.

Perhaps if you provide a code snippet on where you think the goto should be used, you may get responses that satisfy your needs.

I'm not totally against the goto, but I haven't used one - well, I can't remember when. Up to about 5 years ago, a language I use on the System i (aka AS400) known as CL had very few good looping constructs (actually none) and your only choice was to use a goto.

Most languages these days (decent ones) provide adequate constructs with regards to sequence, iterations and decisions that would really make you think long and hard as to why you would need to use a goto.

9868 makes a valid observation regarding breaking out of a nested loop, but it would have to be a really deeply nested loop and if that's the case, then it's more than likely a design issue. However, "modern" languages usually provide a "psuedo" goto (e.g. Java with break and a label) for these situations.

Cheers,
JD