>>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);
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Did you read my link first.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
>>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().
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
#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 <strong>fgets( filename, sizeof filename / sizeof ( char ), stdin );</strong> */
while (filename[i] != "\0"); /* "\0" is a string and is not the same that <strong>'\0'</strong>, 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 */
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
Is your task to input a file name, and convert the filename itself to upper case? Or are you supposed to
1) open the file
2) read the file
3) convert the contents of the file to upper case?
And if you don't take the hint on gets() , we may stop helping you :icon_wink:
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
>>void convert (char filename[]); /* function is defined as char *filename not char filename[], even if it works like that */
they are both the same so it doesn't matter. But they should be consistent not because the compiler will care but because good programming style.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>What should I declard it as.
int, perhaps? And initialize it to 0? i is a counter that starts at the beginning of the string and looks for the null character. Are you really trying to say that you don't understand how an array index works?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
thats what i tried, it ran the program but let me enter a filename then stopped;
void convert(char* filename)
{
int i = 0;
while(filename[i] != '\0')
{
filename[i] = toupper(filename[i]);
<strong>++i; /* increment the counter */</strong>
}
}
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218