| | |
Converting lowercase to capital
![]() |
•
•
Join Date: Oct 2007
Posts: 17
Reputation:
Solved Threads: 0
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.
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #define CHARSIZE 101 int main() { char filename[CHARSIZE]; printf("Enter the filename that you want to open. /n"); gets(filename); toupper(filename); puts(filename); return 0; }
>>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.
>>gets(filename);
Never ever use gets(). use fgets() instead like this:
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.
You might also find the following tutorial useful...
http://www.daniweb.com/tutorials/tutorial45806.html
http://www.daniweb.com/tutorials/tutorial45806.html
*Voted best profile in the world*
•
•
Join Date: Oct 2007
Posts: 17
Reputation:
Solved Threads: 0
have revised, It still doesnt work exactly though
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #define CHARSIZE 101 void convert (char strng[]); int main() { char filename[CHARSIZE]; printf("Enter the filename that you want to open. /n"); gets(filename); convert(filename); puts(filename); return 0; } void convert() { int i =0; while (filename[i] != "\0"); { filename[i] = toupper(filename[i]); i++; } }
•
•
Join Date: Oct 2007
Posts: 17
Reputation:
Solved Threads: 0
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:
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #define CHARSIZE 101 void convert (char filename[]); int main() { char filename[CHARSIZE]; printf("Enter the filename that you want to open. /n"); gets(filename); convert(filename); puts(filename); return 0; } void convert(char* filename) { int i =0; while (filename[i] != "\0"); { filename[i] = tolower(filename[i]); i++; } }
#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.
![]() |
Similar Threads
- uppercase to lowercase url's (Search Engine Optimization)
- Converting uppercase to lowercase help???? (Java)
- Converting lowercase type to uppercase (new programmer) (Java)
- Converting lowercase to capitals (Java)
- Convert first character from lowercase to uppercase? (C)
Other Threads in the C Forum
- Previous Thread: Problem in C program
- Next Thread: prime
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer linked linkedlist linux linuxsegmentationfault list lists locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open opensource owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






