- #include<string.h>
-
main (void){
-
char name[20][20];
-
int i;
-
clrscr();
-
for(i=0;i<=4;i++){
-
printf("Enter the Names:\n",i);
-
scanf("%s",&name[i]);
-
}
-
-
//sorting//
-
-
for(i=0;i<=4;i++){
-
printf("%s\n",name[i]);
-
}
-
getch();
-
return 0;
-
}
here's my running program, but my instructor want it to be sorted alphabetically... so someone help me with this...
its 2 dimensional array of strings but not yet sorted...
pls give me some function how to sort it by alphabetical order...
6 3481
can you use the sort library funtion, e.g.
http://www.cplusplus.com/reference/clibrary/cstdlib/qsort.html
or do you have to write you own?
you can use function strcmp() to compare a pair of strings
http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html
- #include<string.h>
-
main (void){
-
char name[20][20];
-
int i,x;
-
char hold;
-
clrscr();
-
for(i=0;i<=4;i++){
-
printf("Enter the Names:\n",i);
-
scanf("%s",&name[i]);
-
}
-
-
//sorting//
-
-
-
for(i=0;i<=4;i++){
-
for(x=i;x<=4;x++){
-
name[i]="abc";
-
hold[x]="afs";
-
if(name[i]>hold[x]){
-
printf("%s\n",name[i]);
-
else
-
printf("%s\n",hold[x]);
-
}
-
}
-
}
-
for(i=0;i<=4;i++){
-
printf("%s\n",name[i]);
-
}
-
getch();
-
return 0;
-
}
anybody can sort by this by alphabetical order??
to sort pls start at the statement //sorting//
#include<string.h>
main (void){
char name[20][20];
int i,x;
char hold;
clrscr();
for(i=0;i<=4;i++){
printf("Enter the Names:\n",i);
scanf("%s",&name[i]);
}
//sorting//
for(i=0;i<=4;i++){
for(x=i;x<=4;x++){
name[i]="abc";
hold[x]="afs";
if(name[i]>hold[x]){
printf("%s\n",name[i]);
else
printf("%s\n",hold[x]);
}
}
}
for(i=0;i<=4;i++){
printf("%s\n",name[i]);
}
getch();
return 0;
}
anybody can sort by this by alphabetical order??
to sort pls start at the statement //sorting//
No one is going to write your code for you. Horace gave you the tool that you need to compare two strings, why don't you try to use it to compare a few strings and see if you can determine how you might be able to tell which one comes before the other in alphabetical order.
No one is going to write your code for you. Horace gave you the tool that you need to compare two strings, why don't you try to use it to compare a few strings and see if you can determine how you might be able to tell which one comes before the other in alphabetical order.
You should also state what you ment by sorting a 2D array as this could mean a few different things. Also describe any restrictions and post your solution (working or not) so that we can see that you are trying.
Adrian
thats it, i don't know how to do it the sorting part, thats y i need your help...
I assume you are sorting the 2D char array (char name[20][20]) as above.
Then I would assume this means that as you increase the first index (name[0], name[1], ... , name[19]), the strings stored in the second index (name[0][0] through name[0][19]) should be getting lexicographically larger, or alphabetically larger. If you have "Animal" and "Baseball", then "Baseball" is lexicographically larger - thus, "Baseball"s index will be greater than "Animal"s.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dr John Stockton |
last post by:
Q1 :
Given an array such as might have been generated by
var A =
is there a highly effective way of reducing it to - i.e.
removing the undefineds and shifting the rest down?
...
|
by: SilverWolf |
last post by:
I need some help with sorting and shuffling array of strings. I can't
seem to get qsort working, and I don't even know how to start to shuffle
the array. Here is what I have for now:
#include...
|
by: Niklas Uhlin |
last post by:
Why does the code below output this:
"v a" (118,32,97)
"w a" (119,32,97)
"v b" (118,32,98)
"w b" (119,32,98)
"v c" (118,32,99)
"w c" (119,32,99)
and not this (as one would expect if...
|
by: Stuart |
last post by:
I am converting a VB6 App.
In the VB6 app, I have a Type structure of about 30 elements (mixture of
booleans, integers, strings and some doubles), in an array of say 20 to
100+ records.
The...
|
by: yeti349 |
last post by:
Hi, I'm using the following code to retrieve data from an xml file and
populate a javascript array. The data is then displayed in html table
form. I would like to then be able to sort by each...
|
by: Rainmaker |
last post by:
Hi,
Can anyone tell me an efficient algorithm to sort an array of strings?
Keep in mind that this array is HUGE and so the algorithm should me
efficient enough to deal with it.
Thanks
|
by: Michael |
last post by:
Hi,
I am trying to pass a function an array of strings, but I am having trouble
getting the indexing to index the strings rather than the individual
characters of one of the strings.
I have...
|
by: David Lazos |
last post by:
Hi All,
I use Contains method of String object to determine if a string variable
has another string, like that.
***************************
ipAddress.Contains("127.0.0")...
|
by: Jerry Spence1 |
last post by:
I'm using VB2005
I have an array of some 500,000 items which are of the form
080715_175327_312.jpg. These are camera frames of the form
YYMMDD_HHmmss_ms.jpg
I want to create another array...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |