Okay well let me first post the dam code
Okay first thing is if i dont put a newline escape sequence in scanf it wont get the charaters typed properly why ???. Like if i dont use the newline escape sequence and if i press a its gonna take in a and a black why???Code:#include <stdio.h> #include <stdlib.h> #include <time.h> #define SIZE 10 struct data{ int num; struct data *nextPtr; }; typedef struct data dataNode; typedef dataNode *DataNodePtr; void rando ( DataNodePtr *, int ); void printlist( DataNodePtr ); int main(void) { int number, cnt =0; DataNodePtr startPtr = NULL; srand(time(NULL)); while ( ++cnt != 25 ){ number = 1 + rand() %100; rando( &startPtr, number ); } printlist( startPtr ); puts(" "); system("PAUSE"); return 0; } void rando ( DataNodePtr *sPtr, int number ) { DataNodePtr newPtr, currentPtr, prevoiusPtr; newPtr = malloc ( sizeof( dataNode)); if ( newPtr != NULL){ newPtr -> num = number; newPtr -> nextPtr = NULL; prevoiusPtr = NULL; currentPtr = *sPtr; while ( currentPtr != NULL && number > currentPtr -> num ){ prevoiusPtr = currentPtr; currentPtr = currentPtr -> nextPtr; } if ( prevoiusPtr == NULL ){ newPtr -> nextPtr = *sPtr; *sPtr = newPtr; } else{ prevoiusPtr -> nextPtr = newPtr; newPtr -> nextPtr = currentPtr; } } else printf( "No memory to store integer %d", number ); } void printlist( DataNodePtr currentPtr ) { int sum=0; if ( currentPtr == NULL ) printf( "List is empty" ); else{ while ( currentPtr != NULL ){ printf( "%d ", currentPtr -> num); sum += currentPtr -> num; currentPtr = currentPtr -> nextPtr; } printf( "\n\nThe sum is %d", sum ); printf("\nThe average is %f", (float)sum/25 ); } }
Okay the main question is this my book says write a programm that creats a link list of 10 characters , then creats a copy of the list in reverse order..
Okay so the copy should be a linked list ??? or in a array ??? I am a bit confused
Cheers



LinkBack URL
About LinkBacks


