yellowSnow 607 Posting Whiz in Training

What input is it waiting for? shouldnt scanf read from the printf line above it. I was using all newBalance before and it was doing the same thing. I am new to this and just generally confused with it sometimes.

Take John A's advice and just use one balance variable (e.g. bal and get rid of newBalance)

Remove these lines just before your while loop:

printf("\n");
    printf("Enter deposit (+) or Withdrawl (-): ");
    scanf("%f", &creditDebit);

You're basically getting all your printfs and scanfs screwed up. Try this for your loop:

while (creditDebit != 0) {

        printf("\n");
        printf("Enter deposit (+) or Withdrawl (-): ");
        scanf("%f", &creditDebit);

        bal += creditDebit;

        if (bal < 0) {
            printf("***I am sorry, you have bounced this check. $10 will be "
                "deducted\n");
            bal -= 10;
        }
        printf("Current balance: %.2f\n", bal);
    }

In your original code snippet, you were printing the current balance and then calling scanf, whereas you need to print your prompt for credit/debit and then call scanf to achieve the output you require.

yellowSnow 607 Posting Whiz in Training

Your printMonth function is returning 0 when it's declared as returning void - lose it.

Line of code - system("PAUSE") is not portable.

Your range of years is rather odd :-/

If you enter a year outside of your range - besides printing the error message, you also print the top part of your calendar (i.e. the days of the week) - minor logic glitch.

In your output, how about printing a header for the month/year such as AUGUST 2009, prior to printing out the calendar month details?

Your day of week calculation, though it works is probably a tad convoluted with all those century and month table calculations. Here's a short function that returns the day number (assuming Gregorian Calendar). Note, it's a bit quick and dirty and doesn't contain any sanity checks for day and month ranges (although the algorithm still works assuming you understand 43rd August 2009 = 12th September 2009 etc). I'll leave the error checking up to you to code if you wish to use this function.

int getDayNumber(int year, int month, int day) {

    int dayNum;

    if (month < 3) {
        month = month + 12;
        year = year - 1;
    }

    dayNum = (day + (2 * month) + (6 * (month + 1) / 10) + year + (year / 4)
            - (year / 100) + (year / 400) + 1) % 7;
    return dayNum;
}

Not sure what you're asking with reference to DOWHILE usage.

yellowSnow 607 Posting Whiz in Training

Your pointer is initialized in a screwed-up way. I think you've got bigger fish to fry first. What do you think you're trying to do with your 'bit array' that isn't already done with masks?

I totally agree with Dave Sinkula's response. Bit masking would be far easier especially if you encapsulate the logic into a function.

If you really want to go down your original path, then try the following code snippet out. It uses a union (not sure if you understand unions). But again, you're better of just using plain ol' bit masking to achieve your goal.

But as Salem pointed out earlier, there is no such thing as an array of bits, so the code below doesn't give you much except for "reading" what those bits in your structure are after loading up character (it really is overkill).

#include <stdio.h>

int main(void) {

    struct bits {
        unsigned char b8 :1,
                      b7 :1,
                      b6 :1,
                      b5 :1,
                      b4 :1,
                      b3 :1,
                      b2 :1,
                      b1 :1;
    };

    union uchar {
        struct bits chbits;
        unsigned char ch;
    } mychar;

    printf("Enter a character: ");
    scanf("%c", &mychar.ch);

    printf("Binary representation of the character %c : %d%d%d%d%d%d%d%d\n", mychar.ch,
            mychar.chbits.b1, mychar.chbits.b2, mychar.chbits.b3,
            mychar.chbits.b4, mychar.chbits.b5, mychar.chbits.b6,
            mychar.chbits.b7, mychar.chbits.b8);

    return 0;
}

Cheers,
JD

yellowSnow 607 Posting Whiz in Training

Well if you think you understood the OP's question, then I query the integrity of your code snippet. You are reading two characters from the file and trying to convert to hex. Perhaps something like this is what you meant:

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

int main(void) {

    FILE *fp;
    int c;

    if ((fp = fopen("test.txt", "r")) == NULL) {
        printf("Error opening file!");
        return EXIT_FAILURE;
    }

    while ((c = fgetc(fp)) != EOF) {
        printf("%x", c);
    }

    fclose(fp);
    return 0;
}

Cheers,
JD

yellowSnow 607 Posting Whiz in Training

An example of what I think he wants to do:
string to convert: "abcdef"
converted string: "616263646566"

You might be on to something there. If your assertion is correct, then Tom Gunn has already provided an adequate response to the OPs other similar post here (with some minor modifications):

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

Cheers,
JD

yellowSnow 607 Posting Whiz in Training

You have a semi-colon at the end of your for statement in your code - that will prevent the prompting and gathering of more than one set of data.

You declare a variable called custDB - I think that should be cust.

You're applying the address-of operator (&) for the char array members of your data structure - that's a NO.

You're not providing an index for your cust array of type Customer when setting your data.

That being said, I have modified your code example to the point where you should be able to tweak it to suit the requirements of your assignment. It will prompt for two "sets of customer data" and print out a subset of that data. I have "chucked" everything into the main function - it will be your exercise to refactor that code into the functions required by your assignment. The rest is up to you.

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

#define SIZE 2 // initially to test kept it to SIZE 2

typedef struct {
    char firstName[30];
    char lastName[30];
    char street[35];
    char city[20];
    char state[3];
    int zip;
    char phone[15];
    int accountId;
} Customer;


int main(void) {

    Customer cust[SIZE]; // an array of Customer type of size SIZE
    int i;

    for (i = 0; i < SIZE; ++i) {

        printf("\n");
        printf("Enter Data for Customer %d\n", i);
        printf("Enter First Last Phone: ");

        scanf("%s %s %s", cust[i].firstName, cust[i].lastName, cust[i].phone);
        printf("Address (Street City State ZIP): ");
        scanf("%s %s %s %d", cust[i].street, cust[i].city, cust[i].state, …
tux4life commented: Very solid post :) +18
yellowSnow 607 Posting Whiz in Training

> string ss="this is an encrytpion program"; Could it be that you meant: char ss[] = "this is an encrytpion program"; here?
Otherwise please clarify.

Besides your correction of the non-existent string type, I can't make any sense of the OP's question?

I think (he or she) is "out with the fairies" - so to speak.
:-/

yellowSnow 607 Posting Whiz in Training

I assume you are trying to count the number of lowercase and uppercase letters entered via stdin and load the counts into two separate arrays.

You need to load the two arrays within the while loop whilst reading characters in from stdin. I would also change the loop condition to check for a newline character as well.

One more thing, using expressions such as c- 'A' and 'A' + j is generally not a good idea. It will work for the ASCII character set but it would break for other character sets. Since this is more than likely an assignment and that's the not so good way teachers and books tend to code these character counting type of programs, we'll leave that discussion for another time.

Since I'm providing code below that corrects your initial issue, I'll leave you with sorting out the details of the search function. At least put some code together and post back if you're having difficulties with it.

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

int main(void) {

    int c, i, j, letter[26], letter2[26];

    /* initialise arrays that hold counts */
    for (j = 0; j < 26; ++j)
        letter2[j] = 0;

    for (i = 0; i < 26; ++i)
        letter[i] = 0;

    /* read characters from stdin and count */
    while ((c = getchar()) != '\n') {
        if (isupper(c)) {
            ++letter2[c - 'A'];
        }

        if (islower(c)) {
            ++letter[c - 'a'];
        }
    }

    /* print tables displaying counts of each letter entered */
    for …