User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Oct 2007
Posts: 5
Reputation: skyah is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
skyah skyah is offline Offline
Newbie Poster

Question Can someone help me with my programming?

  #1  
Oct 16th, 2007
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:
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,755
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Can someone help me with my programming?

  #2  
Oct 16th, 2007
#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;
}
Reply With Quote  
Join Date: Oct 2007
Posts: 9
Reputation: enes is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
enes enes is offline Offline
Newbie Poster

Re: Can someone help me with my programming?

  #3  
Oct 16th, 2007
do you like it.if you want i can send you a good solution
Reply With Quote  
Join Date: Sep 2006
Location: India
Posts: 79
Reputation: parthiban is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
parthiban's Avatar
parthiban parthiban is offline Offline
Junior Poster in Training

Re: Can someone help me with my programming?

  #4  
Oct 16th, 2007
Hi ,

Here's the solution:

  1. #include <stdio.h>
  2. #include <string.h>
  3. #define N_STRINGS 7
  4. #define arrayword 15
  5. #define maxletters 15
  6.  
  7. void sort_words(char[][15]);
  8.  
  9. int main(void)
  10. {
  11. int i;
  12. char line[N_STRINGS][arrayword];
  13.  
  14.  
  15. printf("\nPlease type in %d words : \n",N_STRINGS);
  16. for (i = 0; i < N_STRINGS; ++i)
  17. scanf("%s", line[i]);
  18.  
  19. printf("\nHere is the list you entered:\n\n");
  20. for (i = 0; i < N_STRINGS; ++i)
  21. printf("%s\n", line[i]);
  22.  
  23. sort_words(line);
  24.  
  25. printf("\n\nalphabetically sorted for you:\n");
  26. for (i = 0; i < N_STRINGS; ++i)
  27. printf("%s\n", line[i]);
  28.  
  29. return 0;
  30. }
  31.  
  32. /* Using Bubble sorting technique to sort words */
  33. void sort_words(char words_array[][15])
  34. {
  35. int i,j;
  36. char temp[arrayword];
  37. for(i=0;i<N_STRINGS-1;i++)
  38. {
  39. for(j=i+1;j<N_STRINGS;j++)
  40. {
  41. if(strcmp(words_array[i],words_array[j])>0)
  42. {
  43. strcpy(temp,words_array[i]);
  44. strcpy(words_array[i],words_array[j]);
  45. strcpy(words_array[j],temp);
  46. }
  47. }
  48. }
  49. }

greetings
Parthiban
Reply With Quote  
Join Date: Sep 2004
Posts: 6,515
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 489
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Can someone help me with my programming?

  #5  
Oct 16th, 2007
>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.
I'm here to prove you wrong.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 5:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC