![]() |
| | #1 |
| Registered User Join Date: May 2008
Posts: 70
| |
| overlord21 is offline | |
| | #2 |
| Registered User Join Date: May 2008
Posts: 70
| i begin with my problem in fact here's what the exercice says:"Write a program that reads an array of strings, sorts the array using the insertion sort, and displays the sorted array. The array can be declared as follows:char str[SIZE][N]; where N is defined as a preprocessing directive make sure you use appropriate string functions such as gets to read a string, and strcpy to perform an assignment. It may sound easy but i hope i will get a response |
| overlord21 is offline | |
| | #3 |
| Registered User Join Date: May 2008
Posts: 70
| it's not a homework its just an exercice i found and i wanted to train with it as i only discover strings in the course! thanks |
| overlord21 is offline | |
| | #4 |
| Registered User Join Date: May 2008
Posts: 70
| Code: /*
#include<stdio.h>
#define SIZE 5
#include <stdio.h>
void print_array(int *);
void read_array(int []);
void sort_array(int *);
int search(int, int[]);
void choice_operation(int []);
int main(){
int ar[SIZE]; //array declaration (SIZE is constant)
read_array(ar); //read array elements
sort_array(ar); //sort the array
choice_operation(ar); //display a list of operations
system("PAUSE");
return 0;
}
void read_array(int x[]){
int i;
printf(" Enter the array: ");
for (i = 0 ; i < SIZE ; i++)
scanf("%d",&x[i]);
}
void sort_array(int ar[])
{
int i, j;
int tmp;
for (j=1; j < SIZE; j++)
{
tmp = ar[j];
for (i = j; (i > 0) && (ar[i-1] > tmp); i--)
ar[i] = ar[i-1];
ar[i] = tmp;
}
printf(" Array sorted succesfully.\n");
printf("\n");
}
int search (int v,int x[]){
int i; for (i = 0 ; i < SIZE ; i++){
if (x[i] == v)
return(i);
}
return(-1);
}
void choice_operation(int x[]){
int i,y=0,sum = 0,a = 0,v;
do{
printf("To display the max and the min of the array, enter 1\n");
printf("To know a position of a value, Enter 2\n");
printf("To find the average, Enter 3\n");
printf("To list the elements of the array, Enter 4\n");
printf("To exit, Enter any other character.\n");
scanf("%d",&y);
switch(y){
case 1:
printf("the max is %d, and the min is %d\n",x[0],x[SIZE-1]);
break;
case 2:
printf("Enter a value to know its position within the array:\n");
scanf("%d",&v);
a = search(v,x);
if(a != -1)
printf("the positions of %d is %d\n",v,a);
else
printf("this element does not belong to the array\n");
break;
case 3:
for (i = 0 ; i < SIZE ; i++)
sum += x[i];
printf("The average is %d\n",(sum / SIZE));
break;
case 4:
print_array(x);
break;
default:
printf("The program ends.\n");
return 0;
}
}
while(y=1);
}
void print_array(int A[])
{
int i;
printf("\n");
printf(" The sorted array is the following \n");
printf("\n");
for(i = 0; i < SIZE ;i++)
printf(" %d\n", A[i]);
}
*/
|
| overlord21 is offline | |
| | #5 |
| Registered User Join Date: May 2008
Posts: 70
| the algorithm above in a program that reads, sort by insertion sort, give the position of a chosen number in the array.... in order to let the user do as much operations as he wants i made a"do while" loop still it works but i don't understand why i had to make while(y=1) to make the menu reapear any suggestings? |
| overlord21 is offline | |
| | #6 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Also, instead of having libraries and books, we should write down all of human knowledge on a single huge piece of paper, that will obviously make everything easier. |
| brewbuck is offline | |
| | #7 |
| Registered User Join Date: May 2008
Posts: 70
| i don't know if its sarcastic, but you surely know that we are only talking about C programming(one topic). So this board won't be overcrowd.... |
| overlord21 is offline | |
| | #8 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| It's sarcasm, because it would be the same as putting together all our knowledge into a single huge piece of paper. In other words - it's bad. What happens if thousands of people start posting their problems in the same topic? Replies all the time, forth and back to each problem. It would become quite the mess. There's a reason why there's a single topic for everything. And don't 5 five times in a row. If you've been to other forums, you would know that double posting is usually bad, triple posting sneered at and 4 times or more usually unheard of, in many cases (unless it's a special type of thread). There's an edit button. I do suggest you learn how to use it.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #9 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,356
| Quote:
Here's a chance to try again: post your question in a new thread. Use an appropriate title and get straight to the point. State what you are trying to do, what you actually did, and how does it not work.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #10 |
| Woof, woof! Join Date: Mar 2007 Location: Australia
Posts: 3,139
| Perhaps you should read the dictionary, for 2 reasons at least. Imagine if the words were unordered, and their definitions were also unordered and on different pages. Now if I asked you to find the meaning of "stupid" in 500,000 words it'd take you hours. Not to mention you'd have to know the meaning of "stupid" to find it since the word and it's definition don't match, nor are in order. I don't know if you're having a laugh, or just looking for a post count. Presumably you're a human, you categorize everything into an object, if you didn't you wouldn't work. |
| zacs7 is offline | |
| | #11 |
| Registered User Join Date: May 2008
Posts: 70
| humans are such criticizing beings |
| overlord21 is offline | |
| | #12 |
| Registered User Join Date: Apr 2008
Posts: 100
| tHAT IS HOW WE IMPROVE!! by criticizing! |
| Leojeen is offline | |
| | #13 |
| Registered User Join Date: May 2008
Posts: 3
| HELP PLEASE I have a project to do where the teacher gives us a .dat file and we have to put it into an array. this .dat file will be added to the directory the run with the program as a.out < scores.dat. Please tell me how to do this. Assignment: You job is to write a program that will read in the golf scores of several players in a golf game. You will then display some statistics about the scores. You will generate an average score and list those players who scored below the average (a good thing!) You will also provide the functionality to show the winning score. The player with the lowest score is the winner. Below is the main() function you must use in your program: int main() { int scoreList [MAX_PLAYERS]; /* Array to store golf scores */ int numberOfPlayers = 0; /* Total number of scores entered */ float averageScore = 0.0; /* Average golf score */ int winningScore = 0; /* The lowest score */ printf("\nWelcome to CMSC104's Golf Statistics Program!\n\n"); /* Fill array with golf scores */ numberOfPlayers = FillGolfScoreList (scoreList); Thankyou |
| programnewbie is offline | |
| | #14 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| 1) It's better to start a new thread. And 2) No, we're not going to help you unless you can show that you are capable of doing this. Start with as much as you can, show it and ask specific questions you do not understand. We can guide you, but we cannot give you the answers.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
![]() |
| Tags |
| arrays, c programming, problems, programming, strings |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| No clue how to make a code to solve problems! | ctnzn | C Programming | 8 | 10-16-2008 02:59 AM |
| C Pointers Problems | mhelal | C Programming | 8 | 01-10-2007 06:35 AM |
| String Manipulation problems -_- | Astra | C Programming | 5 | 12-13-2006 05:48 PM |
| Rendering problems (DirectX?) | OnionKnight | Tech Board | 0 | 08-17-2006 12:17 PM |
| DJGPP problems | stormswift | C Programming | 2 | 02-26-2002 04:35 PM |