Aia 1,977 Nearly a Posting Maven

thanks ^.^ that woulda caught me up in the future. how can i create a net to catch a letter input and return the error message? what i have up there seems to be the simplest way, but it doesnt work >.< i get a infinite loop

You have an amazing computer right there. Your program should crash.

scanf("%i", &choice); /* missing the & */

But forget all together scanf for picking characters. Too many problems with the extra left in the standard buffer stream.
Use fgets().

char choice[3];
do
{
	if ( fgets( choice, sizeof choice, stdin ) )
	{
		if ( choice[1] != '\n' )
		{
		 	while ( getchar() != '\n' );
		}
		switch (choice[0])
		{
			case '1':
				puts( "You chose 1" );
		   		break;
		  	case '2':
			   	break;
		  	default:
			   	printf("Your choice is invalid, please try again.\n");
                                break;                   
		}
	}
}while(choice[0] != '2');
Aia 1,977 Nearly a Posting Maven
void ClearGameBoard(char board[]);

That's it a prototype of the function. Inside the switch, the call should be:

ClearGameBoard( board ); /* board is the name of any given string */
Aia 1,977 Nearly a Posting Maven

I did the same thing that you did on more than 1 computer and i get the same problem. Lets say u wanna convert 255 from base 10 to base 10. Youre supposed to get 255 as the answer, howeever i am getting 254. when i try to convert any number from 100 up from base ten to any other base i am getting the answer as 1 short the correct answer.

The problem is in the way your compiler deals with this particular statement:

sum+= n*pow(fromBase,j);

You are loosing value. sum is an integer, but the result of the multiplication of n and pow() is a float. The conversion to integer looses some value.
A couple of simple printfs will show the case:

int toBaseTen(char array[256], int fromBase)
{
    int i,j;
    int arraylen;
    int n;
    int sum=0;
         
    arraylen=strlen(array)- 1;
    
         for(i=0,j=arraylen-1;i<arraylen,j>-1;i++,j--)
         {
	          n = (array[i] - '0');
              printf( "n = %d;  n*pow( fromBase, j ) = %.2f\n", n, ( n*pow(fromBase, j)) );
              sum+= n*pow(fromBase,j);
              printf( "sum = %d\n", sum );
              
         }
    return sum;
}
/* input/output:
Enter number :255
Enter base of input: 10
Enter base of output: 2

n = 2 n*pow( fromBase, j ) = 200.00
sum = 199
n = 5 n*pow( fromBase, j ) = 50.00
sum = 249
n = 5 n*pow( fromBase, j ) = 5.00
sum = 254
11111110
Press any key to continue . . .
*/

As you see the first sum should have shown a value of …

Aia 1,977 Nearly a Posting Maven

Basically, I am trying to copy the "message" to the "menu" and then display using the
*(menu+i) and *menu notation.

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

void restaurant(char*);
void restaurante( char *menu, int size );

int main() {

    char message[17] = { 'W', 'h', 'a', 't', 's', ' ', 'f', 'o', 'r',
            ' ', 'l', 'u', 'n', 'c', 'h', '?', '\0' };
    int i, *mPtr;

    restaurant(message);
    putchar( '\n' );
    restaurante( message, strlen( message ) );
    getchar();

    return 0;
}
void restaurant(char* menu) {
    while ( *menu )
    {
        printf( "%c", *menu );
        ++menu;
    }
}
/* or */
void restaurante( char *menu, int size )
{
    int i;
    for ( i = 0; i < size + 1; i++ )
    {
        printf( "%c", *( menu + i ) );
    }
}
Aia 1,977 Nearly a Posting Maven

Aiks, i really fresh in C. Your coding contain some element i never learn before.

Learning is a process always on going.

i copy paste the code and run it, it work perfectly.:)

No copy and paste. Write it. Practice. Write it again. Practice again.
You'll learn nothing by just coping and paste and looking at it, and rejoicing that it works.
You don't know that it works until you understand why it does.

Cannot you use std::string apis ?
>i never learn about it. :$ haha

That's not C. Don't pay attention to it.

Aia 1,977 Nearly a Posting Maven

Never define main as void return. Start defining main as int main( void ) or int main ( int argc, char *argv[] ) if you are expecting arguments from the command line.

>Sorry i never learn about <ctype.h>, isalpha, islower and isupper, is there other way???

#include <stdio.h>
/* #define ALL_CHARACTER */ /* enable for use all characters in RANGE */
/* #define RANGE */  /* enable for only lower case */
#ifdef RANGE
#define START 'a'
#endif
#ifndef RANGE
#define START 'A'
#endif

int main( void )
{     
    char character[256] = { 0 };
    int c = '\0';
    
    puts( "Enter some text:" );
    
    while ( ( c = getchar() ) != '\n' && c != EOF )
    {
        ++character[c];
    }
    for ( c = START; c <= 'z'; c++ )
    {
#ifndef ALL_CHARACTER
        if ( character[c] )
#endif
            printf( "%c = %d\n", c, character[c] );
    }
    getchar();
    return 0;
}
Aia 1,977 Nearly a Posting Maven

strcpy(secOnes,zero); needs to be strcpy( secOne, zero );
i needs to be declared so it does y.

Aia 1,977 Nearly a Posting Maven

Needs some changes:
initialpos(&patom[0],N); instead of initialpos(patom[0],N); the & is needed if you want to pass it the address of a structure.
void initialpos(struct atom *name[], int N) instead of void initialpos(struct atom *name, int N) *name[] is the beginning of the array of structures.

Aia 1,977 Nearly a Posting Maven

>but it still doesn't work.
What's not working?. What's supposed to happen and it isn't?.
You forgot to change the arguments also in the printf().

Aia 1,977 Nearly a Posting Maven
void initialpos(struct atom *name, int N)
{    
    int i;
    
    for (i = 0; i < N; i++)
    {
        name[i].x=drand48()*20;
        name[i].y=drand48()*20;
        name[i].z=drand48()*20;
        printf("pos of %d: %f\t %f\t %f\t \n", i, name[i].x, name[i].y, name[i].z);
    }
}

Taking this as an example:
name.x=drand48()*20;
You are assigning to a field of a structure, but that is not a field of a structure. It is a pointer to a field of a structure. It can be done in two ways:
(*name).x = drand48() * 20; or
name->x = drand48() * 20;
Same thing is going on with the others and even with the parameters in the printf();

Aia 1,977 Nearly a Posting Maven

Obviously string is recognized as equal, temp it's not.
At first I thought it was because of the lack of '\0' but in the example

if(local == input) compares the value of pointer local which is a memory location against the value of pointer input which could be the same memory location or another one.

Maybe this modification to your code throw some light to the matter; take a look at the extra printf() and at the memories addresses in the output :

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

void compare(char* input);

int main() {

  char *string;
  char temp[4];

  string = "Bye";

  temp[0]='B';
  temp[1]='y';
  temp[2]='e';
  temp[3]='\0';
    
  compare(string);
  compare(temp);

  return 0;
}



void compare(char* input){

    char *local = "Bye";

    if(local == input) printf("\nRecognized as equal!\n\n");
    else printf("\nRecognized as different!\n\n");

    /* display what local is pointing to */
    printf ("pointer local says \"%s\"\n", local);

    /* display what input is pointing to */
    printf ("pointer input says \"%s\"\n", input);

    /* display the value these two pointers hold in storage */
    printf ("Memory address value store in pointer `input\' = %p\n", input);
    printf ("Memory address value store in pointer `local\' = %p\n\n", local);

}

/* output:
Recognized as equal!
pointer local says "Bye"
pointer input says "Bye"
Memory address value store in pointer `input' = 00403000
Memory address value store in pointer `local' = 00403000

Recognized as different!
pointer local says "Bye"
pointer input says "Bye"
Memory address value store in pointer `input' = 0022FF70
Memory address value store in pointer `local' …
Aia 1,977 Nearly a Posting Maven

You guessed the core of the problem.
I've seen some sscanf() tutorials but I've not understood the difference with strtok().
In my case, there's no way to perform a "on the fly" conversion using i.e. atoi()
something like:
numbers = atoi(p);
dunno why it doesn't work!
ps: my variable numbers it's a pointer to an array of int, maybe I missed a couple of parenteses so it looked like an array of pointers of type int..

Here's the changes for your code to work using sscanf() to read the integer.

int numbers[nums]; /* this needs to be an array of integers */
    .
    .
    .
     while (p != NULL)
     {
        sscanf(p, "%d", &numbers[i]); /* scan string for an integer */
        ++i; 
        p = strtok (NULL, ",;");
     }

numbers = atoi(p);
dunno why it doesn't work!

You need to make numbers an array of integers and not an array of pointers of type int. Right now you are trying to assign whatever atoi(p) gives you to a pointer memory which it can only hold the address of another memory and not an integer value.

Aia 1,977 Nearly a Posting Maven

Hi guys, I've got troubles with a conversion.

int *numbers[nums];  /* this is an array of pointers of type int */
      
    char *p; /* this is a pointer to a string */
    
     numbers[i] = p; /* You are trying to assign a string to an element of the array of pointers type int */

That doesn't work. You need to convert the number value store in the string pointed by `p' into integer before storing in numbers.
Maybe use sscanf() to read the value from the string.

Aia 1,977 Nearly a Posting Maven

When compiling with Borland C it worked fine. However when I tried cimpiling it with VS 2005 I got the following error:
"Unhandled exception at 0x00413529 in Learning C.exe: 0xC0000005: Access violation writing location 0x00415645."

But based on what I learnt in C I don't understand why it did not work in VS. And why by making it an array rather than a pointer it made a difference?

char *name="Yankee Duddle"; is a constant, it can not be modified.
char name[]="Yankee Duddle"; the elements can be modified.
calling the SET_BIT in main you are trying to modify the value in char *name.

[EDIT]: Sorry, SPS your posted while I was writing this. Making this post a repetition.

Aia 1,977 Nearly a Posting Maven

You are calling this function the wrong way. You are passing the wrong arguments.
This is how the function is declared.
float price( const float ticket, int *num );

accept first an unchangeable float that's what const means, and a pointer to an int variable. OK? Now let's take a piece of your code where you call this function.


DailyChild = price( &DailyChildNum, DChild );

use are passing &DailyChildNum as the first argument. What is it?. The address of an int.
price only accepts a const float. Can you understand? Wrong type of variable and it cannot be the address.
Let's look at the second argument: DChild.
What is it? const float DChild = 1.50; A const float. What should be there? A pointer to an int. Something like &DChild if that were an int, which is not.
It seems that you have them switched.

By the way there's not reason for that function to not be declared after main like the others and prototyped at the beginning like the others.

Aia 1,977 Nearly a Posting Maven

>how would I be able to display the amount of either nails or screws purchased


Here's where you need some knowledge about variable scope and pointers.
First: piece is a local variable declared in the price function which it will be destroyed as soon as the function exits.
We need to keep those values obtained by the function price alive. How?. We can declare in main some variables to hold the values, and them pass those variables as pointers to the function.

Example:

/*
 * HomeDepot.c
 * Shows how to match item with price.
 */
#include <stdio.h>

/* function price has now two parameters
 * a float for the price
 * a pointer type int for the item
 * returns a float for total price times item
 */ 
float price( const float item, int *piece )
{
   char newline;
   
   scanf( "%d%c", piece, &newline ); /* amount of items */
   
   return item * (*piece); /* piece is a pointer to another variable, to access  what's in that variable you have to use the * operand to dereference it */
}

int main( void )
{
   const float screw = .50;  /* this never should change */
   const float nail = .25; /* this never should change */
   float price_screws = 0.00;  /* final total price  items */
   float price_nails = 0.00;  /* final total price items */
   /* new variables */
   int A_nails = 0;      /* amount of nails wanted */
   int A_screws = …
Aia 1,977 Nearly a Posting Maven

char tickettype[];
This array needs a subscript limit inside the brackets.

To improve your code and skills I suggest you do some reading
about:
Scope. The life and range of variable declarations.
Global variables.
And the key word switch.
At some point you will have to star using pointers in the
functions to avoid all those Global variables.

Aia 1,977 Nearly a Posting Maven

What I'm trying to do is make it so that when a ticket is purchased for a child that is accomapanied by 2 or more adults or if accompanied by 3 or more seniors they get 10 percent off of the total purchase.

Do you realize that you only have to check if a child is accompanied by two adults to recieve the discount? I know that seniors might be another "species of their own", but they are, also, adults.

Your code is pretty hard to read, right now.
It is custumary to declare the functions after the closing bracket of main and declare the prototypes of those functions before main.
Right now you have a function at the top and the rest at the bottom.

#include <iostream>
is for C++. C should be <stdio.h>

A few lines of comments indicating what expressions do, would help you also. Specially functions.

Bonus example:

/*
 * line.c
 * Shows how to use an independent function to print a line of
 * stars and newlines.
 */
#include <stdio.h>

void PrintAStarLine( int star, int newline ); /* prototype */

int main( void )
{
   PrintAStarLine( 80, 4 );  /* give it any arguments you want */
   getchar();
   return 0;
}

/*
 * PrintAStarLine: Prints a line of star characters
 * parameters: a int for the amount of char stars, a int for amount   of newlines
 * return void.
 */
void PrintAStarLine( int star, int newline ) …
Aia 1,977 Nearly a Posting Maven

Next time you post your code you need to write those square brackets, or highlight all your code and click in the # symbol.

[
CODE=C] Your code inside here ...[/CODE]

Aia 1,977 Nearly a Posting Maven

>Now just to figure out this calculation problem
I think I know what your want to do, but I am not sure.
Perhaps this piece of code will demostrate an example of how to do it.

/*
 * HomeDepot.c
 * Shows how to match item with price.
 */
#include <stdio.h>
 
float price( const float item )
{
   int piece = 0;
   char newline;
   
   scanf( "%d%c", &piece, &newline ); /* amount of items */
   
   return item * piece;
}

int main( void )
{
   const float screw = .50;  /* this never should change */
   const float nail = .25; /* this never should change */
   float price_screws = 0.00;  /* final total price  items */
   float price_nails = 0.00;  /* final total price items */
   
   
   /* ask for nails */
   printf( " Enter amount of nails: " );
   fflush( stdout );             /* refresh the screen */

   /* get & compute the total price of nails */
   price_nails = price( nail );
   
   /* ask for screws */
   printf( "Enter amount of screws: " );
   fflush( stdout );             /* refresh the screen */

   /* get & compute the total price of screws */
   price_screws = price( screw );
   
   /* final display */
   puts( "\n\tYour total order" );
   puts( "\t================\n");
   printf( " Price for nails: %6.2f\n", price_nails );
   printf( "Price for screws: %6.2f\n", price_screws );
   printf( "     Grand total: %6.2f\n", price_nails + price_screws );

   getchar();
   return 0;
}
/* 
 my input / output.
  Enter amount of nails: 34
Enter amount of screws: 23

        Your total order
        ================

 Price for nails: $  8.50
Price for screws: $ 11.50
     Grand total: $ 20.00

*/
Aia 1,977 Nearly a Posting Maven

>I'm pretty much on my way to success!
I am glad of that optimism. Even when you become famous, remember that you could stop by at anytime. :)

Aia 1,977 Nearly a Posting Maven

>I would use a different code but my instructor wants us to use printf/scanf coding specifically

Well, if you must use scanf() let's learn about it correctly, shall we?
Let's look at this function, as an example:

void GetInput(void)
{
    printf("Customer Name (First Middle Last): ");
    scanf(" %s %s %s", &customerName);
    printf("\n\n\n");
    return;
 }

scanf(" %s %s %s", &customerName);
There's not chance this is going to fly.
First: You are trying to read a string. The proper arguments for that are:
scanf( "%s", customerName ); you don't want the & operator there. & is only for integers and solo chars.
I suppose you could write something like:
scanf( "%s%s%s", first_array, second_array, third_array );
passing to it three different arrays but don't do it.
scanf() stops reading from the buffer as soon as encounters a space.
That implies that if the user enters name, middle name and last name. You code goes where many codes has gone before.
What can you do?. One way is to tell scanf how much you want to read. It is not pretty but doable.
scanf( "%[^\n]", customerName ); This statement tells scanf to read until it encounters a newline. But it leaves that newline behind in the stdin buffer.
To pick that newline we could write it like:

char newline;

scanf( "%[^\n]%c", customerName, &newline );

Don't mention to anyone I told you so. :)

Aia 1,977 Nearly a Posting Maven

I'm still trying to figure out how to get the calculations to work in my program. If someone can shed some light on that area for me, it would be greatly appreciated. Thanks again.

Without trying to discourage you, I have to say your code is full of errors.
My suggestion is that you should work little by little in the steps that
you need to take for you code to work. Compile each of those steps in separate stages and if they work implement them together. That way the bugs would have a harder time compounding.

Let's look at any of your functions. All seems to be suffering of the same problems.

void HowManySeniors(void)
{
    
    DailySenior = 1.25;
    YearlySenior= 3.75;

    printf("\n");
    printf("#of Seniors:   ");
    scanf(" %d", &seniorNum); 
    printf("\n");

    if (seniorNum <= 999) 
    {
    }
    else 
    {
    printf("Invalid Number Entered, please try again.");
    printf("\n\n\n");
    system("pause"); 
    HowManySeniors();
    }

    

    return ;

}

DailySenior = 1.25;
YearlySenior= 3.75;
Nothing is using those values inside the function, therefore no reason to be there.
scanf(" %d", &seniorNum);
scanf() is nothing but a lot of grief for any one that uses it. Specially, if you read strings with it. Avoid using that function.
Here's a couple of links that would help you to understand better.

http://www.daniweb.com/tutorials/tutorial45806.htm
http://www.daniweb.com/code/snippet266.htmli
http://www.gidnetwork.com/b-59.html

if (seniorNum <= 999)
{
}
What are you trying to do with that if? That construction is …

Aia 1,977 Nearly a Posting Maven

with sprintf i got some more luck, but when I print it later on, there is some junk that is printed after it

If printf is displaying garbage is because you are missing the '\0' ( null
terminator ) at the end of the string. You need to add it.

Do you know the difference between 'x' and "x"?

Aia 1,977 Nearly a Posting Maven

You are having a little bit of a problem with the subscripts in the multi-dimensional array. In order for you to reference them correctly, you need a nested loop.

int i, x;

for( i = 0; i < MAXA; i++ )
{
    for( x = 0; x < len; x++ )
    {
         ...Here goes the switch.
    }
}

This statement will give you ALWAYS the length of the first string, by virtue of x = 0. It needs to be inside the first loop and before of the second loop, so you can obtain the length of the current working on string. Right now you are using the lenght of the first string for every case.

len = strlen( last_name[x] ) + 1;

You are ALWAYS trying to convert to upper case whatsoever lives at the last position of the multi-dimension, which doesn't contain any part of your inputed string.

switch(last_name[x][FL] = toupper( last_name[x][FL] ) )

The swith should be inside the second loop, and if you use the same
indexes it would be like

switch( last_name[i][x] = toupper( last_name[i][x] ) )
Aia 1,977 Nearly a Posting Maven

thanks for clarification, the only way I knew to do it is put (float) before it.

as for the errors, not everything is smooth; I just had to change the variables to doubles.

Thanks everyone for all the input, much appriciated.

Best Regards
DeathEvil

In C the function modf() is always double. However you could use instead the function modff() which is for floats.

Aia 1,977 Nearly a Posting Maven

>there are parts in between that I cut out but are irrelevant because compiler complains only about integer_part variable

Make the variables double instead of floats and you'll be fine.
BTW, main returns an int, so it should be int main( void ) and not
void main( void )

Aia 1,977 Nearly a Posting Maven

no I wasn't, I was just calling the function up. Looks like that's fixed it, thanks!

Yes, you were just missing a variable that would hold the value passed by the return of the function.

about the fflush, I know its wrong but I guess since I'm a beginner it's easier to just tell me to use that while learning the basics since portability will be an issue later, but for now everyone is using the same compiler so all is well and you can add that to the article which lead me to this site, "What Are They Teaching C Programmers These Days?"

I certainly understand what you are saying. However , if I may, I would like to encourage you to try to learn without the use of this flushing practice.
Why? Would you ask.
Because it creates a habit and a process of thinking that is different that the process to do right source files.

For example. If all that you are concern with is the flushing of the stdin buffer you could just write a little function to do just that:

void flush_it( void )
{
    int ch;
    
    do
    {
        ch = getchar();
    }
    while( ch != '\n' && ch != EOF );
}

However the concern is not if we should flush or not to flush. I'll say that the concern should be the way we would obtain the input from the user.

Aia 1,977 Nearly a Posting Maven

Are you calling in main the function deposits() like this?:

int number_of_deposits;

number_of_deposits = deposits();

fflush(stdin); is a no-no. Here's a link why not to use it.

Aia 1,977 Nearly a Posting Maven

Thanks man, by the time I checked I got ready almost the same thing except I used if instead of switch. Very much appreciated.

Best Regards
DeathEvil

You're welcome. I don't know if that is how professionals would do it,
but that's one way I would.

Aia 1,977 Nearly a Posting Maven

Thanks guys, I will try to make something out of it, but that sounds like a good starting point. If anyone alse has any suggestions, please feel free to input your thoughts

Given a string without undesirable characters like '\n', etc...

*
 * abbr.c
 * Converts string to upper case and removes vocals
 */
#include <stdio.h>
#include <ctype.h>

int main( void )
{
    char name[]= "Jackson100";    /* given string */
    int i = 0, x = 0;    /* indexes */
    int len = strlen( name ) + 1;    

    /*  Make string to upper case and removing vocals */
    for( i = 0; i < len; i++ )
    {
        switch( name[i] = toupper( name[i] ) )
        {
            case 'A':
                break;
            case 'E':
                break;
            case 'I':
                break;
            case 'O':
                break;
            case 'U':
                break;
            default:
            {
                name[x] = name[i];
                ++x;
            }
        }
    }
    printf( "%s\n", name );    /* for testing purposes */
    
    getchar();
    return 0;
}

/* output: JCKSN100 */
Aia 1,977 Nearly a Posting Maven

Perhaps begin with a function called 'isVowel()', which returns true or false, depending on the type of letter passed to it.

Then implement your own 'strcpy' like function, which makes use of isVowel()

I would convert all the characters to upper case first, using toupper()

Aia 1,977 Nearly a Posting Maven
if(strcmp(full_name[index[inner]],full_name[index[inner+1]])>0)

if first string is longer than second string.

temp=index[inner],index[inner]=index[inner+1],index[inner+1]=temp;

swap.

Aia 1,977 Nearly a Posting Maven

^ He's the SpoilSport one. And he really looks like his avatar. What's not to like?

Aia 1,977 Nearly a Posting Maven

my bad man, didn't realize it was such a big deal, no need to be hostile. sorry.

Next code you post do the same thing you did last, but write (code=c)
instead of (code). That would set the proper formatting for c code.

You posted the same code that I gave you as an example. You haven't done anything to it. You are asking for help about Qsort.
Please, post any tries that you have done by yourself using that type of sorting. Then, it is more likely that someone will help you.

Aia 1,977 Nearly a Posting Maven

westsiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiide loool people i don't know what you guys have against smoking peopl

Hamada_1990 you are going back to your old habits of writing.
Just a friendly remainder. :)

Aia 1,977 Nearly a Posting Maven

Now if this doesn't make you want to quit smoking, I don't know what will.

I know. Nicotine will take care of you.

Aia 1,977 Nearly a Posting Maven

Is this supposed to be a C program or VB? I moved this thread into the C board because the code posted in the original thread looked like C code, but maybe I was wrong. Aia's post looks like VB because that's the way it would be coded in VB. If this is about VB then just say so and I'll move it again into the correct board.

You could always move it to the C.Net forum. ;)
Sorry could not help it.

Aia 1,977 Nearly a Posting Maven

ok man from now on i will write proper english for you who don't like my way of writting

And we will appreciate it. Thank you.

Aia 1,977 Nearly a Posting Maven

don't you have to use endif to every if statement? I'm not sure in VB though

I not quite sure what you are talking about. However this is how you would do a nested if in seudocode.

IF (logical-expression) THEN
   statements
   IF (logical-expression) THEN
      statements
   ELSE
      statements
   END IF
   statements
ELSE
   statements
   IF (logical-expression) THEN
      statements
   END IF
   statements
END IF
Aia 1,977 Nearly a Posting Maven

o How many levels of nesting are there in this design?

Concerning this question, allow me to rearrange your seudocode so
you can see it better.

input X

if (0 <= X and X < 49)
output "you fail"

else
    if (50 <= X and X < 70)
        output "your grade is" X
        output "you did OK"

    else
        if (70 <= X and X < 85)
            output "your grade is" X
            output "you did well"

        else
            if (85 <= X and X < 100)
                output "your grade is" X
                output "you did great"

endif
output "how did you do?"

Some of the other questions can be answer if you make this seudocode into an actual program. Then you can test your answers.

Aia 1,977 Nearly a Posting Maven

Hurray, hurray. Long live the Queen. The Queen Dani.

OK. people. I say hurray. Can I get my good rep now?.
This thread has become a `gold mine' in good reps.

WolfPack commented: Here. +10
arjunsasidharan commented: I agree ;) +3
Aia 1,977 Nearly a Posting Maven

Was that English?

No wonder that he said:

ppl i have no idea wut u ppl are talkin about

joshSCH commented: Did you just call me queer? Hm.. -3
Aia 1,977 Nearly a Posting Maven

It's the same code apparently, so why the different answers when compiled with gcc?

Because we just entered The Outer Limits?.
Darn it!. I knew my tax software was cheating me.

Aia 1,977 Nearly a Posting Maven

!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.

I know how to keep myself clean since the time when my mother taught me how to do it. However I am not quite sure I ever learned how to block myself.

Aia 1,977 Nearly a Posting Maven

Right to left.
First variable evaluated is the i++. ( i = 5 ) 5 is assigned for the right most %d.
It gets incremented to 6 before is evaluated again. ( i = 6 ).
Next %d gets 6 assigned to it. Not incrementation here.
Last %d gets 6 because the decrement is after being assigned to be printed.
That's how I see it.
6, 6, 5

Aia 1,977 Nearly a Posting Maven

The correct answer is that the result is undefined, or unpredictable. It depends on the compiler -- the answer by some compilers may be 5,5,5 because only the last version is stored. Yet other compilers, such as VC++ 2005 Express will give 6,5,5.

And others will give you 6, 6, 5 like it should be.

Aia 1,977 Nearly a Posting Maven
/*
 * r_ascii.c
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MAX 126
#define MIN 33

int randy( int max, int min )
{
    int r_num;
    do
     {
        r_num = rand();
    }
    while ( r_num < min || r_num > max );
    return r_num;
}

int main( void )
{
    int i;
    
    srand( (unsigned) time( NULL ) );
    
     
     for( i = 0; i < 1000; i++ )
     {
        printf( "%c ", randy( MAX, MIN ) );
    }
    getchar();
    return 0;
}

Output:

b U * = ^ s y F c ; ^ x 5 v - k L 1 0 M r a n c w 4 o 5 w = : ' - 7 ? v ; L $ )
4 ? D I P r d y { D @ e p & O Y C L T % y f U h ( i F , p 8 D [ ^ < p W | V z |
2 : 1 * = 1 n q V & r F X { ] c ) > ] I O ? < < * ! U l W O ' h [ 1 g { x z % I
# R J L ) U : < ( % 9 + 6 S 8 q } , i . 8 O Z ; s D j i y W n o } P z ` i ^ i K
A 2 ] " 5 / …
Aia 1,977 Nearly a Posting Maven

>That should work
No, it won't. Please test your code before posting.

>only thing I'm not sure about is if I should have a return rnd statement at the end

int randomChar() returns a type int. That should give you a clue.

Aia 1,977 Nearly a Posting Maven
/*
 *    random_ascii.c
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

char *randy( char *ascii, int len )
{
    char *ptr = ascii;
    int i;
    
    for( i = 0; i < len; i++ )
    {
        *( ptr + i ) = rand() % 94 + 33;
    }
    *( ptr + i ) = '\0';
    
    return ptr;    
}

int main( void )
{
    char random_s[20] = { '\0' };
    int i;
    
    srand( (unsigned)time( NULL ) ); 
        
    puts( "\tGive me some random lines\n" );
        
    for( i = 0; i < 10; i++ )
    { 
        randy( random_s, sizeof random_s / sizeof ( char ) );
        printf( "\t%s\n", random_s );
    }
    
    getchar();
    return 0;    
}

Output:

Give me some random lines

        /$[=qeML2Q>qiq,3t@Y&
        3+Nf/)B%FBH<|t6\_[m<
        NWM'?\%z~A$5)t-K*<TK
        l.Spi{p6-~,CZb1h&@qb
        l<2J=d?r~>#TZdlEC)_3
        O_;/ND4EayBi@TvR3bet
        ow'kh^OX>jj"\4{I25|o
        z2QC)=,szJG.Sv]9!I;m
        Ofg~mdF%snDUnwPjuoHL
        ASUR/+W">)kuOi~!fq2z