•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,554 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,485 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 561 | Replies: 4
![]() |
•
•
Join Date: Oct 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
I have to write an interactive program using scanf() to read in seven strings input by the user. The program should print the seven strings as a list, then sort them alphabetically and print a new list. I have to use the function strcmp() to assist in the sorting of the strings and also use the preprocessing directive #define N_STRINGS 7. The program must sort a different number of strings by changing only that line. This is what I have so far.
#include stdio.h
#include string.h
#define N_STRINGS 7
#define arrayword 15
#define maxletters 15
int main(void)
{
int i, j, c;
char line[N_STRINGS][arrayword];
char temp[maxletters];
printf("\nPlease type in %d words : ",N_STRINGS);
for (i = 0; i < N_STRINGS; ++i)
scanf("%s", line[i]);
printf("\nHere is the list you entered:\n\n");
for (i = 0; i < N_STRINGS; ++i)
printf("%s\n", line[i]);
printf("\n\nalphabetically sorted for you:\n");
for (i = 0; i < N_STRINGS; ++i)
printf("%s\n", line[i]);
return 0;
}Error 1 error C2006: '#include' : expected a filename, found 'identifier' c:\documents and settings\skyah\my documents\visual studio 2005\projects\10 10\10 10\10 10.cpp 1
Error 2 fatal error C1083: Cannot open include file: '': No such file or directory c:\documents and settings\skyah\my documents\visual studio 2005\projects\10 10\10 10\10 10.cpp 1
PLEASE HELP ME IF YOU CAN.
Can someone please help me? These are the error messages i received:
#include stdio.h
#include string.h
#define N_STRINGS 7
#define arrayword 15
#define maxletters 15
int main(void)
{
int i, j, c;
char line[N_STRINGS][arrayword];
char temp[maxletters];
printf("\nPlease type in %d words : ",N_STRINGS);
for (i = 0; i < N_STRINGS; ++i)
scanf("%s", line[i]);
printf("\nHere is the list you entered:\n\n");
for (i = 0; i < N_STRINGS; ++i)
printf("%s\n", line[i]);
printf("\n\nalphabetically sorted for you:\n");
for (i = 0; i < N_STRINGS; ++i)
printf("%s\n", line[i]);
return 0;
}Error 1 error C2006: '#include' : expected a filename, found 'identifier' c:\documents and settings\skyah\my documents\visual studio 2005\projects\10 10\10 10\10 10.cpp 1
Error 2 fatal error C1083: Cannot open include file: '': No such file or directory c:\documents and settings\skyah\my documents\visual studio 2005\projects\10 10\10 10\10 10.cpp 1
PLEASE HELP ME IF YOU CAN.
Can someone please help me? These are the error messages i received:
#include <stdio.h>
#include <string.h>
#define N_STRINGS 7
#define arrayword 15
#define maxletters 15
int main(void)
{
int i, j, c;
char line[N_STRINGS][arrayword];
char temp[maxletters];
printf("\nPlease type in %d words : ",N_STRINGS);
for ( i = 0; i < N_STRINGS; ++i )
scanf("%s", line[i]);
printf("\nHere is the list you entered:\n\n");
for ( i = 0; i < N_STRINGS; ++i )
printf("%s\n", line[i]);
printf("\n\nalphabetically sorted for you:\n");
for ( i = 0; i < N_STRINGS; ++i )
printf("%s\n", line[i]);
return 0;
} Hi ,
Here's the solution:
greetings
Parthiban
Here's the solution:
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> #define N_STRINGS 7 #define arrayword 15 #define maxletters 15 void sort_words(char[][15]); int main(void) { int i; char line[N_STRINGS][arrayword]; printf("\nPlease type in %d words : \n",N_STRINGS); for (i = 0; i < N_STRINGS; ++i) scanf("%s", line[i]); printf("\nHere is the list you entered:\n\n"); for (i = 0; i < N_STRINGS; ++i) printf("%s\n", line[i]); sort_words(line); printf("\n\nalphabetically sorted for you:\n"); for (i = 0; i < N_STRINGS; ++i) printf("%s\n", line[i]); return 0; } /* Using Bubble sorting technique to sort words */ void sort_words(char words_array[][15]) { int i,j; char temp[arrayword]; for(i=0;i<N_STRINGS-1;i++) { for(j=i+1;j<N_STRINGS;j++) { if(strcmp(words_array[i],words_array[j])>0) { strcpy(temp,words_array[i]); strcpy(words_array[i],words_array[j]); strcpy(words_array[j],temp); } } } }
greetings
Parthiban
>Here's the solution:
Great. Now the OP has learned absolutely nothing from this exercise. I hope you end up working with someone who breezed through school without having to learn, because then you'll realize why giving away the entire solution like that hurts more than it could possibly help.
Great. Now the OP has learned absolutely nothing from this exercise. I hope you end up working with someone who breezed through school without having to learn, because then you'll realize why giving away the entire solution like that hurts more than it could possibly help.
I'm here to prove you wrong.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
api apple asm assembly x86 programming hla demo blogger blogging c c++ ccna cocoa code coding competition compiler compilers computer debugging developer development errors evaluation framework gdata google high-performance innovation java languages linerider mcse microsystems networking news next object online open oriented planning platform practices programming python rss software step steps sun tools tutorials xml
- Shell Programming (Shell Scripting)
- Programming (C++)
- Where to get started with Web Programming (IT Careers and Business)
- Programming in Linux? (*nix Software)
- Help Me on Symbian(OS) Programming with c++ (C++)
- Good books on Shell Programming/Perl (Perl)
- Efficient Programming (Computer Science and Software Design)
- New To Programming = ME!! (C++)
Other Threads in the C Forum
- Previous Thread: can someone help me with this C programm
- Next Thread: sscanf() in a loop



Linear Mode