Toupper

problem is in toupper loop.Name is not changing to upper case.I have this code in long program but I have compiled it in short for checking.Not working both places.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//Not Working

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>


int main()
{
	int max_y=50;
	int mid_x=40;
	char name[10];
	fstream temp;
	gotoxy(1,10);
			clreol();
			cout<<"Enter Filename to delete:";
			gets(name);
			int len=strlen(name);
			for(int i=0;i<len;i++)
				toupper(name[i]);
			cout<<strlen(name)<<" "<<name;    //output in lower case
			getch();
			char chh;
			gotoxy(mid_x-strlen("Are you sure to delete Program?")/2,max_y/2);
			cout<<"Are you sure to delete Program?";
			chh=getch();
			if(chh=='y' || chh=='Y')
			{
				strcat(name,".CPP");
				temp.open(name,ios::nocreate);
				if(!temp)
				{
					clrscr();
					gotoxy(mid_x-strlen("File not present!!!!!")/2,max_y/2);
					cout<<"File not present!!!!!";
					getch();
				}
				remove(name);
				gotoxy(mid_x-strlen("File Deleted!!!!!")/2,max_y/2+1);
				cout<<"File Deleted!!!!!";
				getch();
			}
	return 0;
}
toupper doesn't change the argument you pass to it. Instead it returns the uppercase of the argument so you have to do name[i] = toupper(name[i]);.
Instead of

1
2
3
int len=strlen(name);
for(int i=0;i<len;i++)
	toupper(name[i]);


you could write

for ( char *p = name; *p; ++ p ) *p = toupper( *p );
thanks for help.I studied that but forgot it today.
Again thanks for help
Topic archived. No new replies allowed.