yellowSnow 607 Posting Whiz in Training

Here's what I have so far. I am trying to enter a number and convert the number entered into hours, minutes and seconds. I must use "pass by reference" in my code.

#include<stdio.h>

void time(int, int*, int*, int*); //Function Prototype

int main(void)  //function header


{
    int hold;
    float total;
    
    
    printf("Enter the number of seconds ->");
    scanf("%d",&total);
    scanf("%d", &hold);
    return 0;
}  // end of main function

    void time (int total, int *hours, int *min, int *sec) // Function header Line
       {
           int rem1, rem2;
          *hours = total / 3600;
           rem1 = total % 3600;
           *min = rem1 / 60;
           rem2 = rem1 % 60;
         printf ("the number of hours is ->", *hours);
         printf ("the number of minutes is ->", *min);
         printf ("the number of seconds is ->", *sec);  
        }

Here are some observations on the code you have posted.

- I'm not sure why you have declared the variable hold. I'm assuming that the variable total is supposed to be the total number of seconds that will be the input to your time function. That being the case, then it should be declared as int.

- In main you don't even call your time function. You haven't declared variables for hours, minutes and seconds as well. These should be declared and their addresses should be passed to the time function you have defined (there's your pass by reference).

- In your time function, you haven't calculated the number of seconds and you don't need the rem2 variable …

yellowSnow 607 Posting Whiz in Training

Hi
Modify this where possible

And what exactly do you want to modify? Ask a specific question.

yellowSnow 607 Posting Whiz in Training

With the char* string case you're trying to modify a string literal.
This link to the C FAQ explains it better:
http://c-faq.com/decl/strlitinit.html

yellowSnow 607 Posting Whiz in Training

Ok here we go:

- you're missing the semi-colon after your declaration of the variable n.

- you haven't declared the variables i and count. And you don't need the count variable. Just print the value of i.

- remove the semi-colons from the end of your for statements - you have empty for statements here and that is why you are not getting the desired output.

- when counting back, initialize i to n-1.

- the code to print the required output should be part of an else clause - that way, if invalid data is entered, you don't end up printing erroneous values after printing your error message.

- in the future, use code tags when posting code - read the information at this link to learn how to do this:
http://www.daniweb.com/forums/thread93280.html

yellowSnow 607 Posting Whiz in Training

You're over-complicating this a bit. Have a look at the following snippet and see if you can follow what it does:

for (j = NUMBEROFBITS-1; j >= 0; --j) {
        if (i & (1 << j))
            putchar('1');
        else
            putchar('0');
    }

NUMBEROFBITS is defined as the number of bits in an int for your system - for example let's say it's 32. The variable i is your input value.

yellowSnow 607 Posting Whiz in Training

Try:

sprintf(myStrings, "%02X%02X%02X%02X", myHexas[0], myHexas[1], myHexas[2], myHexas[3]);

And use unsigned char for your data type.

yellowSnow 607 Posting Whiz in Training

error was simple. The function was encapsulated into main rather than outside. However, my desired result is not coming out. Now I need some suggestions with the actual code. Thanks!

Gees, you really like doing things the hard way. Here's a simple code snippet that outputs the character:hex representations of each character of a string. See if you can incorporate some aspects of the code into your project.

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

int main(void) {

    char str[] = "ABCDEFG";
    int i;

    for (i = 0; i < strlen(str); ++i) {
        printf("%c:%x ", str[i], str[i]);
    }

    return 0;
}
yellowSnow 607 Posting Whiz in Training

ok my bad I found out there was trailing crap from a previous scanf that was bunging things up.. and that flush is useless.... but I may have more questions.. so I want mark te thread as solved yet.

You're making this more difficult than it needs to be and fflush(stdin) is undefined behaviour according to the standard (although some compilers probably support it).

Take a look at the code snippet below (minus the GetAChar() function):

#include <stdio.h>

void MainMenu() {
    char selection = '\0';
    do {
        printf("Bla Bla.. ");
        printf("Please make your selection (1, 2, 3 or 4): ");
        //selection = GetAChar();
        selection = getchar();
        switch (selection) {
            case '1':
            case '2':
            case '3':
                printf("You selected %c\n", selection);
                break;
            default:
                printf("Whatever!\n");
                break;
        }
        // consume any additional chars entered up to and including
        // the newline character
        while (getchar() != '\n');

    } while (selection != '4');

    return;
}

int main(void) {

    MainMenu();
    return 0;
}

Try the code out and see if you can incorporate aspects of it into your project.

yellowSnow 607 Posting Whiz in Training

Add -Wall option when you compile. (ignore!!_

Sorry another brain fart. You need to pass the address of the parameters to your swap function like so:

swap (&i, &j);
yellowSnow 607 Posting Whiz in Training

now im stuck as to how to display it in decending order

Well you've almost done it. Change the comparison in your strcmp() to be "greater than" (>) to sort the names in descending order. In addition to studying up on why gets() is a poor function (use fgets() instead), study up on the strcmp() function as well to understand why a "greater than" comparison will give you the names in descending order.

yellowSnow 607 Posting Whiz in Training

THanks guys, lol but still stuck on the program, the one thing that has me lost , could you guys tell me if the loop area could be improved? Currently i tried to redo the program and declared my statement just like you guys told me to but i somehow feel the program crashes due to the loop not being complete

Try the following code snippet out and see if it matches your requirements. I'm assuming that you just wish to detect a single character input and when the correct key is entered, display a "successful" type message and exit the program. Otherwise keep on prompting the user with that "scary" message if he/she does not input the correct key.

#include <stdio.h>

int main() {
    char KEY = 'a';
    int Guess;

    printf("You have traveled the World's Deserts and you have finally found the cave\n"
                "of Ali Baba. You see the cave shut, and you shout the secret words:");

    while ((Guess = getchar()) != KEY) {
        // this line "flushes" the input buffer
        while (getchar() != '\n');
        printf( "You hear the sound of hooves closing in on you its the bandits, Please hurry and try again\n");
    }
    printf("You have opened the Cave and took all the riches of the Bandits, Well Done \n");

    // pause program - enter any key + ENTER to terminate the program
    getchar();
    return 0;
}

A couple of things to note:
1) Using the getchar() function, you need to flush the input buffer to …

kvprajapati commented: I like the way you answer. +17
yellowSnow 607 Posting Whiz in Training

Fair enough. But this is a C forum. ;-)

yellowSnow 607 Posting Whiz in Training

Just having a quick look at your code, you're not declaring your variables of type SYM correctly - you need to prefix the declarations with "struct". If you don't want to do this, you'll need to use a typedef.

yellowSnow 607 Posting Whiz in Training

>>scanf("%s",&Guess);
The "%s" tells scanf() that Guess is a pointer to a character array, not a single character. If all you want is a single character then call getchar() instead. (link)


If you want them to enter "open sesame", which is two words separated by a space, then its a lot easier to declare Guess as a character array then use fgets()

char Guess[80] = {0};
fgets( Guess, sizeof(Guess), stdin);

To add to AD's suggestions, I would get rid of the system("pause") function call and replace this with getchar() as well. I'm assuming you are doing this because you are running the program from within an IDE and you want to pause execution of the program to give you enough time to observe the output.

yellowSnow 607 Posting Whiz in Training

@konohastar.

We'll let you off this time ;) since that was your first post, but in future please use code tags when posting code. You'll find members of this forum more willing to help you out if you do this. Read the material at this link to learn how to post code correctly:

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

yellowSnow 607 Posting Whiz in Training

This would have to be close to one of the most stupid assignments I've ever heard of. It just supports my claims on the quality of CS education these days.

yellowSnow 607 Posting Whiz in Training

the moving r and basechars made it fail but initializing the k to zero did the trick.

Thanks very much to you and many thanks to salem :)

Not sure why moving those declarations outside the loop would make it fail - it works for me:

#include <stdio.h>

#define SIZE 64

int main(void) {
    int d, b, k=0, i, r;
    char result[SIZE];
    char basechars[] = "0123456789ABCDEF";

    printf("Enter decimal and base:  ");
    scanf("%d", &d);
    scanf("%d", &b);

    if (b < 2) {
        printf("Your base is too low! \n");
    } else if (b > 16) {
        printf("Your base is too high! \n");
    } else if (d == 0) {
        printf("%d \n", 0);
    } else {

        while (d != 0) {
            r = d % b;
            d = d / b;
            result[k++] = basechars[r];
        }
        for (i = k - 1; i >= 0; --i) {
            printf("%c", result[i]);
        }

    }
    return 0;
}

BTW - if you're happy with the outcome - flag the post as solved.

yellowSnow 607 Posting Whiz in Training

Initialize k to zero.
Also, move your declarations for r and basechars outside of the loop.

Kombat commented: Very Helpful +1
yellowSnow 607 Posting Whiz in Training

Wow thanks it works however it is showing a lot of weird symbols along with the answer.

Post your full code.
And don't thank me - Salem is the one you should be thanking.

yellowSnow 607 Posting Whiz in Training

You're making this more difficult than it needs to be. Look at this code snippet:

while (d != 0) {
        r = d % b;
        d = d / b;
        result[len++] = basechars[r];
    }

    for (i = len-1; i >= 0; --i) {
        printf("%c", result[i]);
    }
yellowSnow 607 Posting Whiz in Training

For the OP - if I'm understanding your issue correctly, you are still experiencing problems getting the strcmp() function to return the fact that two strings are equal.

This is happening because the fgets() function stores the newline character into the buffer and then you are comparing this buffer to a string which you think is the same but it doesn't have the '\n' character. You need to overwrite the '\n' character with a NULL.

Because I'm sick of seeing this thread going nowhere (and I've had a good day at work), here's some code for you to try. Here's the "constraint.txt" file I used:

a1,b1,c3,
a2,b1,c3,
a3,b2,c2,
a2,b3,c1,
a3,b2,c1,

Here's the code that reads the above file into the const_array and then tries to find a string that is equal to append_test_data.

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

int main(void) {

    FILE *fp = NULL;
    char const_array[100][100];
    char append_test_data[100]="a2,b3,c1,";
    int ctr= 0, i = 0;
    char *p = NULL;

    // open constraints file
    if ((fp = fopen("constraint.txt", "r")) == NULL) {
        printf("Cannot open constraint file.\n");
        return EXIT_FAILURE;
    }

    // read file and load each line of text into array
    // don't forget to overwrite the '\n' that fgets reads into the buffer
    while (fgets(const_array[ctr], 100, fp) != NULL) {
        if ((p = strchr(const_array[ctr], '\n'))) {
            *p = '\0';
        }
        ctr++;
    }

    // check constraint against append data
    for (i = 0; i < ctr; i++) {
        if (strcmp(const_array[i], append_test_data) == 0) {
            printf("Append data is …
yellowSnow 607 Posting Whiz in Training

Hello every one?I have a program use to copy the contents of an array to a File.But it does not work. when it runs Visual Studio starts to debug. But nothing happening.File contents does not change.Please help me tho solve this problem.Thank you very much.
Here is the program.

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

int main()
{
FILE *f;
int i=0;
int data[]={1,2,3,4,5};


if((f=fopen("D:\data\def.txt","w"))==NULL){
	printf("File can't open.\n");
}
else{
	for(i=0;i<5;i++){
		fprintf(f,"%s\n",data[i]);
	}
}

}

In your fopen() function call, change '\' characters to '/' in your path. Alternatively, you can escape the '\' character by using "\\".

Other issues:

Your main is supposed to return an integer - you're missing a return statement at the end of your code in main().

Your format specifier in fprintf (i.e. the %s) is wrong. You are writing integers so you need to use %d.

yellowSnow 607 Posting Whiz in Training

You called from main() like
saveToFile(*client_file, &client); //at 33 line
but you should call this function as
saveToFile(client_file, &client);

this may be solve your problem..........

It already did solve the problem sunshine. Refer to post #11!

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

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

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

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

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

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

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

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

yellowSnow 607 Posting Whiz in Training

<rant>
For crying out loud, is this a forum on how to shortcut the English language? Sometimes it feels like it's a tutorial on how to read friggin' SMS messages.

Then u noe hw 2 use do-while loop mar?

u=you, noe=know,hw=how, 2=to, mar=anyone's guess

Could u gv me the website tat can download c programing the notes n the example? Thx^^

u=you, gv=give, tat=that, n=and, thx=thanks

I am too very new in C... I ll try to solve ur prob.....

ur=your,prob=problem

Here's the deal; in the examples I quoted, there is a difference of 19 characters between the crapshoot spelling and the correct spelling (not counting whatever the hell "mar" means).

Get on board and at least try to use proper English.
</rant>

Salem commented: Layin' down the law! +36
yellowSnow 607 Posting Whiz in Training

I think you would have to look at the ncurses library .. or the pdcurses library for the Window's equivalent to avoid any platform specific requirements.

yellowSnow 607 Posting Whiz in Training

You're talking syntax .. I was talking about the overall approach which IMO is far more important than syntax.

yellowSnow 607 Posting Whiz in Training

I should have posted this in my previous blurb. Here's a link to a sticky post at the head of the C forums page:

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

yellowSnow 607 Posting Whiz in Training

@OP
I apologise if this remark seems a little out of place with respect to your query, but I would suggest that you look at using an up-to-date setup. Turbo C is pretty dated.

Personally, for the Windows platform, I would recommend the MinGW toolchain in conjunction with your favourite editor or IDE. Codeblocks is a good IDE option and you can download it with MinGW as part of the package.

I use MinGW in conjunction with the CDT tooling in Eclipse. It works well - except that there are still some integration issues with the gdb debugger - but it's not a "show-stopper".

jephthah commented: truth +14
yellowSnow 607 Posting Whiz in Training

I still think the OP's better option is to keep main() simple and let the other functions (as prescribed in the assignment) do "the work". Use the main code in my previous post as a template.

@RobBrown
Here's a heads up for the function that would prompt the user for input and load the array.

void createArray(int arr2D[][COLSIZE]) {

    int row = 0, col = 0;

    printf("Please enter the data for our %d by %d array:\n", ROWSIZE, COLSIZE);
    for (row = 0; row < ROWSIZE; row++) {
        for (col = 0; col < COLSIZE; col++) {
            scanf("%d", &arr2D[row][col]);
        }
    }
}

I would suggest adding another line of code (via printf) to instruct the user of the program to enter COLSIZE integers each separated by a space and then pressing ENTER. That way you get a row of input at a time.

Using the above code as a template it should be a relatively straightforward exercise to code the "print array " and "sum array" functions.

A little hint for the "print array " function: you need to check when to print a newline character so that your output matches the requirement specified in the assignment (i.e. printing 5 integers per line of output). You can do this using modulo arithmetic (via the % operator).

Cheers,
JD

yellowSnow 607 Posting Whiz in Training

Just a few points:

Always use curly braces for your for statements (and other control mechanisms as well e.g. while) - it will save you a lot of heartache especially later on if you decide to add more lines of code that should be executed as part of the for statement.

Keep your for loops encapsulated within your functions - there should be no reason to have them in main(). Your main function should be very simple and short - it should only have to call the three functions for creating, displaying and summing the array. For example:

int main (void) {

    int myArray[ROWSIZE][COLSIZE];

    createArray(myArray);
    printArray(myArray);
    printf("The total of all elements in our array is %d\n", sumArray(myArray));

    return 0;
}

If you have learnt about function prototypes, then use them to declare your functions.

As I said in another thread earlier, write some pseudocode to work out in your head how to solve the problem before any coding. Get one function working first (e.g. getting user input into 2-d array) before moving onto the next function.

Good luck!

yellowSnow 607 Posting Whiz in Training

Please try to phrase your question a little better.

From the looks of the signature of your ParseCh function (and the somewhat hazy definition of your function) it appears that you want to parse a string of tokens delimited by the ',' character and return the first and last tokens.

If this is the case, then perhaps you should try using the strtok() function.