Toymods Car Club
www.toymods.org.au
F.A.Q. F.A.Q.    Register Register    Login Login    Home Home
Members Members    Search Search
Toymods » General Car Talk » WAY OT: C programmers, I know there are some of you out there

Show: Today's Posts  :: Show Polls 
Email to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
AuthorTopic
THE WITZL
Forums Junkie


Toymods Social Secretary

Location:
Sydney
Registered:
July 2002
 
WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 07:47 Go to next message
Ok, this is waaaay outta left feild i know. But i am desperate.

Im having serious issues comprehending the use of pointers and structures. Im particular with an assignment i have for uni, which is due on monday.

The assignment is to do the following: "allow the user to enter an arbitrarily long string of characters from the keyboard, and when the user types the carriage return character (enter), your program should print all of the characters onto the screen in reverse order".
And it MUST use a stack, in the form of the following structure:

struct node
{
char ch;
struct node *ptr_node;
}


and then use the functions
int pop(struct node **top);
void push(struct node **top, char ch); /* not sure if char ch should be same as in the struct definition */
int is_empty(struct node *top);

The main first hurdle i face is how to read the charcters from the scanf operation into a node struct and then pass it to the push function everytime a character is pushed! Im lost! Sad

HELP!
  Send a private message to this user    
Ribbo
Forums Junkie


I supported Toymods

Location:
Northern Beaches
Registered:
May 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 08:16 Go to previous messageGo to next message
I think you can use a function getchar()

eg.

ch = getchar()
  Send a private message to this user    
Ribbo
Forums Junkie


I supported Toymods

Location:
Northern Beaches
Registered:
May 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 08:20 Go to previous messageGo to next message
hmmm actually
well you could use that, which would process it each time the user pushes a key

let me read the assignment again and have a think of a better way Smile

we did a similar assignment last year Smile

and I nearly got a high destinction hehe

[Updated on: Sat, 24 May 2003 08:20]

  Send a private message to this user    
Ribbo
Forums Junkie


I supported Toymods

Location:
Northern Beaches
Registered:
May 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 08:33 Go to previous messageGo to next message
can't fully remeber how C works, we are doing c++ now

char* input;
char* ch;
int number;
scanf("%s", &input);


number = sizeof(input)/sizeof(char)
while(ch!=input[0])
{
ch = malloc(sizeof(char));
*ch = input[number];
push(ch);
number--;
}

something along those lines, havn't included the struct stuff but this would be the idea id say...
now back to my assignments Smile

[Updated on: Sat, 24 May 2003 08:34]

  Send a private message to this user    
THE WITZL
Forums Junkie


Toymods Social Secretary

Location:
Sydney
Registered:
July 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 09:29 Go to previous messageGo to next message
hooray! thanks dude Smile

that does help a fair bit. I was having issues linking all the bits i've learned over the years, you know how it gets sometimes....

  Send a private message to this user    
stylez
Regular


Location:
Canberra
Registered:
October 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 09:30 Go to previous messageGo to next message
no need for my input eh, good work ribbo

[Updated on: Sat, 24 May 2003 09:32]

  Send a private message to this user    
THE WITZL
Forums Junkie


Toymods Social Secretary

Location:
Sydney
Registered:
July 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 09:40 Go to previous messageGo to next message
oops... forgot one thing.

I've totally blanked on what the ch!=input[0] part means. I think i missed that lecture Sad

I understand the rest and can work with it, but the ch! operator has me temporarily baffled
  Send a private message to this user    
Ribbo
Forums Junkie


I supported Toymods

Location:
Northern Beaches
Registered:
May 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 12:53 Go to previous messageGo to next message
the
ch != input[0]

its saying
while ch does not equal to the first character of your input

so that it stops when it gets to the beginning of your string

Im not sure if you can use the != like this though if its comparing the address or the values....
in c++ you have strings which makes it a little easier and can't remeber with c.

if you are still stuck I could spend a couple minutes and try remember exactly how to do it if this doesn't work Smile
  Send a private message to this user    
Ribbo
Forums Junkie


I supported Toymods

Location:
Northern Beaches
Registered:
May 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 13:46 Go to previous messageGo to next message
just did a quick run through of code and there are some problems in it, that im getting core dumps
and a few problems, one more thing
ch = malloc(sizeof(char)); should be
ch = (char *) malloc(sizeof(char));

it gets you a start anyway

if I had time id love to do it as a little fun to remeber C, but I don't Sad
  Send a private message to this user    
THE WITZL
Forums Junkie


Toymods Social Secretary

Location:
Sydney
Registered:
July 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 14:03 Go to previous messageGo to next message
its all good mate.. i took what you gave and used that as a starter to kick start my recollection of all things C.
Never touched C++, dont think i will either.

I avoided using the dyanmic memory allocation (malloc) and an array like you have done so far, since there is no real limit to the number of characters the user can enter for the sting before they hit enter, and C DOES NOT LIKE getting arrays that don't have pre-defined size (compilers spew at you!).

Instead i am still trying to figure out a way that either each character is automatically "scanned in" or "input" when the key is pressed, and does not wait for the return key to be presses, and thusly have each character dealt with like that. Although this is proving annoying.
The alternative im not 100% sure on..... Rolling Eyes

I have aced this subject thus far, and this assignment only being worth 15-20% of my mark... i should be fine. Especially if i go ahead and do the "optional advanced assignment" worth up to a BONUS 20 marks.

<edit> gimme a soldering iron, a pcb, some microcontrollers and other fun stuff ANYDAY.

[Updated on: Sat, 24 May 2003 14:05]

  Send a private message to this user    
Ribbo
Forums Junkie


I supported Toymods

Location:
Northern Beaches
Registered:
May 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 15:12 Go to previous messageGo to next message
well use getchar() if you want to process as each key is pressed

hehe oops my thing up there would be find to print something backwards
but to put it on a stack like you want, then you want to run through it from beginning to end. Not end to front like ive done
  Send a private message to this user    
shinzui
Regular


Location:
Brisbane
Registered:
November 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sat, 24 May 2003 22:47 Go to previous messageGo to next message
i've got a c program from an assignment that reads a text file of any length without allocating memory. you might be able to change it to suit your case. If you would like a copy, let me know.
  Send a private message to this user    
wilbo666
Forums Junkie


Location:
Brisbane
Registered:
May 2002
Re: WAY OT: C programmers, I know there are some of you out there Sun, 25 May 2003 00:12 Go to previous messageGo to next message
I have a document with some good stuff on calloc, malloc, and realloc if you need it.

Cheers
Wilbo
  Send a private message to this user    
shinzui
Regular


Location:
Brisbane
Registered:
November 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Sun, 25 May 2003 03:53 Go to previous messageGo to next message
anyone know anything about two level page tables? i have to implement one in C and i'm having a few troubles..
  Send a private message to this user    
Nark
Forums Junkie


Location:
Cabramatta, NSW
Registered:
May 2002
      Nark@toymods.net/Work
icon9.gif  Re: WAY OT: C programmers, I know there are some of you out there Mon, 26 May 2003 07:11 Go to previous messageGo to next message
*shudder*

C sux0rz. Thanks for reminding me of how much it truly does suck though... Glad I'm a Java programmer again... hehe
  Send a private message to this user    
THE WITZL
Forums Junkie


Toymods Social Secretary

Location:
Sydney
Registered:
July 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Mon, 26 May 2003 12:35 Go to previous messageGo to next message
bastard java guy.
  Send a private message to this user    
Nark
Forums Junkie


Location:
Cabramatta, NSW
Registered:
May 2002
      Nark@toymods.net/Work
icon10.gif  Re: WAY OT: C programmers, I know there are some of you out there Mon, 26 May 2003 23:37 Go to previous messageGo to next message
Two words: Dynamic Strings

Mwuahahaha!!
  Send a private message to this user    
THE WITZL
Forums Junkie


Toymods Social Secretary

Location:
Sydney
Registered:
July 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Tue, 27 May 2003 02:25 Go to previous messageGo to next message
Max, as has been said a few times before:

"You are gay and you eat poo"
  Send a private message to this user    
Ribbo
Forums Junkie


I supported Toymods

Location:
Northern Beaches
Registered:
May 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Tue, 27 May 2003 08:55 Go to previous messageGo to next message
don't worry it took his java program 10 minutes to put that string onto the screen Very Happy
  Send a private message to this user    
isaac
Regular


Location:
Helensvale, Queensland
Registered:
March 2003
Re: WAY OT: C programmers, I know there are some of you out there Tue, 27 May 2003 10:09 Go to previous messageGo to next message
I have 3 C++ books for sale if anybody is interested. isaac@islade.com Razz
  Send a private message to this user    
Ribbo
Forums Junkie


I supported Toymods

Location:
Northern Beaches
Registered:
May 2002
 
Re: WAY OT: C programmers, I know there are some of you out there Tue, 27 May 2003 20:58 Go to previous messageGo to next message
what books they are and where you are located would be nice Smile
  Send a private message to this user    
isaac
Regular


Location:
Helensvale, Queensland
Registered:
March 2003
Re: WAY OT: C programmers, I know there are some of you out there Wed, 28 May 2003 02:35 Go to previous messageGo to next message
Idiots guide to C++, C++ from the ground up second edition, C++ the complete reference third edition
gold coast
  Send a private message to this user    
Nark
Forums Junkie


Location:
Cabramatta, NSW
Registered:
May 2002
      Nark@toymods.net/Work
Re: WAY OT: C programmers, I know there are some of you out there Wed, 28 May 2003 02:39 Go to previous messageGo to next message
Ribbo wrote on Tue, 27 May 2003 18:55

don't worry it took his java program 10 minutes to put that string onto the screen Very Happy


Simple 80/20 rule dude. It'd take me 1/5th the time to write something in Java than in C or even C++.

And despite what C people will tell you, Java ain't that slow. Try using Poseidon or IntelliJ and you'll see how snappy a well written, feature-rich Java program can be.

C is nice, but you spend half the time coding and the other half doing work arounds for deficiencies in the language. Unless you use non-standard libraries (which opens another can of worms).
  Send a private message to this user    
ehendrikd
Forums Junkie


Location:
ballarat
Registered:
April 2003
 
Re: WAY OT: C programmers, I know there are some of you out there Wed, 28 May 2003 04:57 Go to previous message
i think that java is awesome to get an idea going in very little time, but i think the end product should be in c/c++ or java using a fast c/c++ dll/shared library to do the hard work.
  Send a private message to this user    
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic:Old or New School
Next Topic:The Run...
Goto Forum:
-=] Back to Top [=-

Current Time: Wed Jan 22 18:07:27 UTC 2025

Total time taken to generate the page: 0.0095889568328857 seconds

Bandwidth utilization bar

.:: Contact :: Home ::.

Powered by: FUDforum 2.3.8
Copyright ©2001-2003 Advanced Internet Designs Inc.