here i think everyone who finds difficulties should post any C programing problem that we would try to discuss and solve. This would make it easy for users to post their request in one threat instead of hundreds of them.
here i think everyone who finds difficulties should post any C programing problem that we would try to discuss and solve. This would make it easy for users to post their request in one threat instead of hundreds of them.
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
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
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]); } */
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?
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....
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.
Neither will there be overcrowding if each topic had its own thread.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....
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
humans are such criticizing beings
tHAT IS HOW WE IMPROVE!! by criticizing!
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
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.