I am taking C program course and i got some problem about sorting strings, hope someone could help me to solve the problem...
The is the output which suppose to be:
-------------------------
car
house
antidisestablishmentarism
another line of text
C programming is interesting
apple sauce
pumpkin pie
cable TV news
drink of water
yet one more line of text!
1) Print list of strings in the order input.
2) Print list of strings in the reverse order input.
3) Print list of strings in order of length.
4) Quit
-------------------
Enter: 3
Sorted Line #0: C programming is interesting
Sorted Line #1: yet one more line of text!
Sorted Line #2: antidisestablishmentarism
Sorted Line #3: another line of text
Sorted Line #4: drink of water
Sorted Line #5: cable TV news
Sorted Line #6: pumpkin pie
Sorted Line #7: apple sauce
Sorted Line #8: house
Sorted Line #9: car
1) Print list of strings in the order input.
2) Print list of strings in the reverse order input.
3) Print list of strings in order of length.
4) Quit
-----------------------
just want to ask how could i set different quote into different array, so i could compare them?
9 2058
The strings are not supposed to be sorted.
What you are to do is print the strings in the order in which they were entered. This has nothing to do with the contents of the string.
So put the strings in an array as you enter them and then just display the array front to end and end to front.
Post again when you have this working. Then we'll talk about displaying by length.
is that mean.. -
-
if (option = 1 )
-
{
-
printf("car");
-
printf("house ");
-
}
-
-
if (option =2)
-
{
-
printf("yet one more line of text!");
-
}
-
-
since i am not that good at C program...
hope you can explain to me more detail...
If you enter these strings:
car
truck
airplane
then in reverse order these are
airplane
truck
car
If these were sorted by value you would have:
airplane
car
truck
But you are not being asked to do this.
in stead of using the simple method like using [printf]
how do i set [car, truck,airplain] into strings?
Is that original list of strings (car, house, ..., yet one more line of text!) supposed to be typed in by the user or do you think it is ok to "hard-code" that list into your program?
Never mind. I suggest you start by writing functions that accept an array of strings and produce the three kinds of outputs. Whether your main program populates that array from user input or a hard-coded initializer has no impact on the lower level function. Start with a hard-coded initializer so you can focus on the lower level functions. Change it later if you wish. - static const char * const array[] = {
-
"car", "house", ..., "yet another line of text!" };
-
static const int arraysize = (int) (sizeof(array) / sizeof(array[0]));
do you know how to sort a number array??
have you seen the bubble sort??
If you understand bubble sort then ask. I believe you will get help from people over here about how you can effectively use bubble sort to sort your string array. (Bubble sort is the simplest of all sorting)
never heard it before... may be i have learn something similar...
how do i use it to get the out put in order?
Review the replies from weaknessforcats. Option 1 calls for printing the strings in the order of input; no sorting required. Option 2 calls for printing the strings in the reverse order of input; no sorting required. Option 3 calls for printing the strings in order of length; here you will have to sort.
Get options 1 and 2 working first before you worry about sorting. Where do you stand on those?
this is what i have right now, is it correct? -
#include <stdio.h>
-
#include <string.h>
-
#include <stdbool.h>
-
-
-
{
-
printf("car\n", "house\n", "antidisestablishmentarism\n", "another line of text\n",
-
"C programming is interesting\n", "apple sauce\n", "pumpkin pie\n",
-
"cable TV news\n", "drink of water\n", "yet one more line of text\n");
-
printf(" 1) Print list of strings in the order input.\n" ,
-
" 2) Print list of strings in the reverse order input.\n",
-
" 3) Print list of strings in order of the length\n");
-
char c=getcher();
-
-
if ( c == 1)
-
{
-
static const char array[] = (
-
"car", "house", "antidisestablishmentarism", "oanother line of text",
-
"C programming is interesting", "apple sauce", "pumpkin pie",
-
"cable TV news", "drink of water", "yet one more line of text");
-
static const int arraysize = (int) (sizeof(array)/ sizeof(array[0]));
-
)
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shaun |
last post by:
Hello!
I can't seem to get paths and variables working together:
import os
a = 'books'
os.chdir( '/test')
os.mkdir("/test/"a)
the last line does not seem to work. os.mkdir(a) makes the...
|
by: amber |
last post by:
Hello,
Is there a simple way to sort a listbox that contains strings that are
numbers?
My listbox is populated from a database field that has a datatype of string,
but typically contains numbers....
|
by: Blue Man |
last post by:
hello
I am writing an error handling within different classes in asp.net. the
error class reports the Exception E's string to the database.
but it cuts big strings, if i just display the error it...
|
by: Daniel Weinand |
last post by:
hello ng,
i have a problem and a imho an insufficient method of solution.
strings should be sorted by specific text pattern and dispayed
in groups. the strings are stored in a db and have the...
|
by: Martin Fletcher |
last post by:
when I execute
dim strTEMP_DATA as string
strTEMP_DATA = Encoding.ASCII.GetString(rBuffer).ToString
I alway get a string without the closing quote. I see this in the 'Autos'
window, I also...
|
by: |
last post by:
I'm querying Index Server to return search results, both regular properties
and some custom properties I've created. Index Server has this preference
for thinking about information as strings...
|
by: DierkErdmann |
last post by:
Hi !
I know that this topic has been discussed in the past, but I could not
find a working solution for my problem: sorting (lists of) strings
containing special characters like "ä", "ü",......
|
by: Jojo |
last post by:
Hi all,
I was wondering how I can perform formatted output with C++ strings. For
example, suppose I have in plain C:
sprintf(C_string, "%5.2f %6d");
How can I do such a thing with C++...
|
by: Holger |
last post by:
I tried to do this elegantly, but did not come up with a good solution
Sort strings like
foo1bar2
foo10bar10
foo2bar3
foo10bar2
So that they come out:
foo1bar2
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |