4 Replies - 477 Views - Last Post: 11 March 2010 - 07:10 PM Rate Topic: -----

#1 Guest_haidi*


Reputation:

help please in C!

Posted 11 March 2010 - 02:53 PM

Write an ANSI-C program that creates a list of integers. The integers are read
from the standard input. The input integers are separated by spaces, tabs or newlines. You can use
scanf() to read them. Once an integer is read, a node of the following type is created and the
integer is assigned to the data member of the node:

typedef struct node {
int data;
struct node *next;
} Node;

Once a node is created, it is inserted into a linked list. The nodes in the list should be maintained in
the ascending order according to the data member. At the end of the program (i.e., when the user
types Ctrl-D to stop data input), all the integers in the list should be printed to the standard output one
per line in the ascending order by traversing a list. After printing out the integers, your program
should free all the memory space that was dynamically allocated for the list nodes.
A sample run of the program is as follows. Given the following input:
150 6378 150 89 -15
87 0 128
the output of your program should be:
-15
0
87
89
128
150
150
6378
The above sample input and output files have been put into q2.in and q2.out files. You can copy
them from
/cs/course/2031/labs/lab7/q2.in
/cs/course/2031/labs/lab7/q2.out
When there is no input (that is, the user hits Ctrl-D before entering any integer), your program should
output:
The list is empty
You can assume that the input integers (if given) are valid integers so that your program does not
need to check the validity of the user inputs.

Is This A Good Question/Topic? 0

Replies To: help please in C!

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: help please in C!

Posted 11 March 2010 - 02:58 PM

Sorry we will not do your homework for you. You need to show some effort.


[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 Guest_haidi*


Reputation:

Re: help please in C!

Posted 11 March 2010 - 03:09 PM

that's what i did so far..i am really bad at programming so help please:)

#include <stdio.h>

int main()
{
	int x;
	scanf("%d\n", &x);
	typedef struct node {
		int data;
		struct node *next;
	} Node;
	
	return 0;
}

This post has been edited by JackOfAllTrades: 11 March 2010 - 03:17 PM
Reason for edit:: Added code tags.

Was This Post Helpful? -1

#4 Mercurial  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 178
  • Joined: 06-November 09

Re: help please in C!

Posted 11 March 2010 - 06:01 PM

You input one integer - that's all you've done so far? :wheelchair: Bah... This only requires knowledge of pointers and linked lists. You got plenty tutorials on the internet, don't be lazy.
Was This Post Helpful? 0
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: help please in C!

Posted 11 March 2010 - 07:10 PM

Well just to keep you on the right track the standard format for a C program is:

<include headers>

<declare/define types> (like structs)

<declare functions>

<declare/define global scope variables>

<int main>

<define functions>



i.e:
#include <stdio.h>

typedef struct node {
        int data;
        struct node *next;
} Node;


int main()
{
        int x;
        scanf("%d", &x);       
        return 0;
}

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1