Back to Off Topic

IT PROGRAMMING C++

over 10 years

hey I have to turn every letter from a string in capital letter. I don't know how many words there are nor if the first letter is capital or not. this algorithm is not working properly?? Any ideas why? Help please

include <iostream>

include <string.h>

include <fstream>

include <ctype.h>

using namespace std;

ifstream f("atestat.in");

ofstream g("atestat.out");

int main()

{unsigned int n,i,val=32;

char a[50];

f.getline(a,50);

n=strlen(angel);

//a if(a[1]>='a' && a[1]<='z')

cout&lt;&lt;a[1]-val;

else cout&lt;&lt;a[1];

for(i=2;i<=strlen(a);i++)

if((isalpha(a[i-1])==0)&& isalpha(a[i])==1)

cout<<a[i]-val;

else cout<<a[i];

f.close(); g.close(); return 0; }

over 10 years
i'm not sure if you're supposed to be using files or not, but here you go. you can edit it if you are

#include ****
#include ****
#include ****
#include ****

using namespace std;

int main ()
{
int i=0;
char a[50];
char c;
cin.getline(a,50);
while (a[i])
{
c=a[i];
putchar (toupper(c));
i++;
}
system("PAUSE");
return 0;
}
deletedover 10 years
I haven't worked with C++ for a while so I'm kind of rusty on the syntax.

int main(){

char a[50]; //Assuming 50 is max length

f.getline(a,50);

int length = strlen(a);

for(int i=0; i= 'a' && a[i]<='z' ? a[i]-32 : a[i];
cout<
over 10 years
and it's not working ;(
over 10 years
using namespace std;

ifstream f("atestat.in");

ofstream g("atestat.out");

int main()

{unsigned int n,i,val=32;

char a[50];

f.getline(a,50);

n=strlen(a);

//a if(a[1]>='a' && a[1]<='z')

cout<<a[1]-val;

else cout<<a[1];
for(i=2;i<=strlen(a);i++)

if((isalpha(a[i-1])==0)&& isalpha(a[i])==1)

cout<
over 10 years
I remember doing this in Java but I don't feel like digging through those files.
over 10 years
I'm confused. You should have the commands you need to input a word and receive the desired capitalization. Just find out the code you need to output and work from there.
over 10 years
that mistake occurred due to skype c/p (a) = angel
over 10 years
it takes like 1 minute I think I can't see it...and I wanted to say strlen(a)
over 10 years

jWizard says

What is strlen(angel)?? You don't have an angel variable.

The process of converting each letter should be done in a loop. I don't know why you commented out the if statement under strlen(angel).

Your bottom for loop doesn't have an opening bracket so nothing gets looped.




Hey could you please c/p the algorithm and correct the mistake?
over 10 years
This would be a good topic for Gary.
deletedover 10 years
What is strlen(angel)?? You don't have an angel variable.

The process of converting each letter should be done in a loop. I don't know why you commented out the if statement under strlen(angel).

Your bottom for loop doesn't have an opening bracket so nothing gets looped.
over 10 years
for example if my string is

dog Cat *roughness

the output => Dog Cat *Roughness
deletedover 10 years
Can you provide example input/output of your program?
over 10 years
I need to change the lower case to upper case basically