Converting lowercase to capital

Reply

Join Date: Oct 2007
Posts: 17
Reputation: theteamdrunk is an unknown quantity at this point 
Solved Threads: 0
theteamdrunk theteamdrunk is offline Offline
Newbie Poster

Converting lowercase to capital

 
0
  #1
Oct 30th, 2007
I am writing code that accepts a string of a filename, then capitalize the letters, not changing any numbers or special characters. I think I am on the right path, but can some one give a little push to the right direction.
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #define CHARSIZE 101
  6.  
  7. int main()
  8. {
  9. char filename[CHARSIZE];
  10.  
  11. printf("Enter the filename that you want to open. /n");
  12. gets(filename);
  13.  
  14. toupper(filename);
  15.  
  16. puts(filename);
  17.  
  18. return 0;
  19. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,401
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Converting lowercase to capital

 
0
  #2
Oct 30th, 2007
>>toupper(filename);
Nope. toupper() only accepts a singlle character. There are no standard functions that converts the entire string, so you have to write that part youself. Put the below in a loop and you will have it.

filename[0] = toupper(filename[0]);


>>gets(filename);
Never ever use gets(). use fgets() instead like this: fgets(filename,CHARSIZE,stdin);
Last edited by Ancient Dragon; Oct 30th, 2007 at 2:42 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Converting lowercase to capital

 
0
  #3
Oct 30th, 2007
You might also find the following tutorial useful...
http://www.daniweb.com/tutorials/tutorial45806.html
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 17
Reputation: theteamdrunk is an unknown quantity at this point 
Solved Threads: 0
theteamdrunk theteamdrunk is offline Offline
Newbie Poster

Re: Converting lowercase to capital

 
0
  #4
Oct 30th, 2007
have revised, It still doesnt work exactly though
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #define CHARSIZE 101
  6.  
  7. void convert (char strng[]);
  8.  
  9. int main()
  10. {
  11. char filename[CHARSIZE];
  12.  
  13. printf("Enter the filename that you want to open. /n");
  14. gets(filename);
  15.  
  16. convert(filename);
  17.  
  18. puts(filename);
  19.  
  20. return 0;
  21. }
  22. void convert()
  23. {
  24. int i =0;
  25.  
  26. while (filename[i] != "\0");
  27. {
  28. filename[i] = toupper(filename[i]);
  29. i++;
  30. }
  31. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Converting lowercase to capital

 
0
  #5
Oct 30th, 2007
Did you read my link first.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 17
Reputation: theteamdrunk is an unknown quantity at this point 
Solved Threads: 0
theteamdrunk theteamdrunk is offline Offline
Newbie Poster

Re: Converting lowercase to capital

 
0
  #6
Oct 30th, 2007
sorry, I think I was posting when your reply was posted, I am checking it out now.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Converting lowercase to capital

 
0
  #7
Oct 30th, 2007
Please do.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,401
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Converting lowercase to capital

 
0
  #8
Oct 30th, 2007
>>have revised, It still doesnt work exactly though
You need to pass your convert() function the filename because its declared in main() and not visible to convert().
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 17
Reputation: theteamdrunk is an unknown quantity at this point 
Solved Threads: 0
theteamdrunk theteamdrunk is offline Offline
Newbie Poster

Re: Converting lowercase to capital

 
0
  #9
Oct 30th, 2007
I read the link, but dont know how it can help me. I have made a few changes, but cant get the desired result. Here is updated code:
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #define CHARSIZE 101
  6.  
  7. void convert (char filename[]);
  8.  
  9. int main()
  10. {
  11.  
  12. char filename[CHARSIZE];
  13.  
  14. printf("Enter the filename that you want to open. /n");
  15. gets(filename);
  16.  
  17. convert(filename);
  18.  
  19. puts(filename);
  20.  
  21. return 0;
  22. }
  23. void convert(char* filename)
  24. {
  25. int i =0;
  26.  
  27. while (filename[i] != "\0");
  28. {
  29. filename[i] = tolower(filename[i]);
  30. i++;
  31. }
  32.  
  33. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,031
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Converting lowercase to capital

 
0
  #10
Oct 30th, 2007
#include <string.h> /* no need for this include */
#include <stdlib.h> /* no need for this include */

void convert (char filename[]); /* function is defined as char *filename not char filename[], even if it works like that */

printf("Enter the filename that you want to open. /n") /* you need \n which is not the same that /n */

 gets(filename); /* forget about gets, use fgets( filename, sizeof filename / sizeof ( char ), stdin ); */

while (filename[i] != "\0"); /* "\0" is a string and is not the same that '\0', which is what you want; futhermore that ending (;) is screwing the program there, remove it */


 filename[i] = tolower(filename[i]); /*  I though you wanted to convert to uppercase, use toupper() for that */
Last edited by Aia; Oct 30th, 2007 at 8:15 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC