need help with this short code(basic)

I am new to programing and this code is straight off the Deitel "how to program C".
program is suppose to turn lowercase chars to uppercase char.

I ran it in MS visual studio 2010.

1.made a new project
2.and chose win32 /win32console application/console application-empty project
3.add a .cpp file to source file
4.type the code and ran it.

[b]FAULT[/b][color=Red][/color]
There were no errors but program didn't convert chars to upper case.

[color=Red][b]WARNINGS[/b][/color]
Warning 1 warning C4390: ';' : empty controlled statement found; is this the intent? c:userskasundocumentsvisual studio 2010projectsch73ch73ch73.cpp 20 1 ch73



Warning 2 warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details. c:userskasundocumentsvisual studio 2010projectsch73ch73ch73.cpp 24 1 ch73

[u][b][color=Red]CODE[/color][/b][/u]

#include
#include
#include "conio.h"

void conva(char *sPtr);

int main(void)
{
char string[] = "cdfg";

printf("the string before conversion is: %s
",string);
conva(string);
printf("
the string after conversion is:%s
",string);
return 0;
}
void conva(char *sPtr)
{
printf("puka");
while (*sPtr !=''){
if (islower(*sPtr));{
*sPtr=toupper(*sPtr);
}
++sPtr;
getch();
}
}

[u][color=Red][b]OUTPUT[/b][/color][/u]

the string before conversion is: cdfg
puka

Comments

  • : I am new to programing and this code is straight off the Deitel "how
    : to program C".
    : program is suppose to turn lowercase chars to uppercase char.
    :
    : I ran it in MS visual studio 2010.
    :
    : 1.made a new project
    : 2.and chose win32 /win32console application/console
    : application-empty project
    : 3.add a .cpp file to source file
    : 4.type the code and ran it.
    :
    : [b]FAULT[/b][color=Red][/color]
    : There were no errors but program didn't convert chars to upper case.
    :
    : [color=Red][b]WARNINGS[/b][/color]
    : Warning 1 warning C4390: ';' : empty controlled statement found; is
    : this the intent? c:userskasundocumentsvisual studio
    : 2010projectsch73ch73[color=Red]ch73.cpp 20[/color] 1 ch73
    :

    [color=Blue]The warning states the exact place of the problem - it is line #20 in file ch73.cpp and if you look closely on that line you will see that there is a ; character before the { character - remove it and it should work. Please read about IF() statements.[/color]

    :
    : Warning 2 warning C4996: 'getch': The POSIX name for this item is
    : deprecated. Instead, use the ISO C++ conformant name: _getch. See
    : online help for details. c:userskasundocumentsvisual studio
    : 2010projectsch73ch73ch73.cpp 24 1 ch73
    :
    [color=Blue]And again, warning text tells you exactly what to do to resolve it - simply insert an underscore _ before getch() and warning will be gone.[/color]

    : [u][b][color=Red]CODE[/color][/b][/u]
    : [code]
    : #include
    : #include
    : #include "conio.h"
    :
    : void conva(char *sPtr);
    :
    : int main(void)
    : {
    : char string[] = "cdfg";
    :
    : printf("the string before conversion is: %s
    ",string);
    : conva(string);
    : printf("
    the string after conversion is:%s
    ",string);
    : return 0;
    : }
    : void conva(char *sPtr)
    : {
    : printf("puka");
    : while (*sPtr !=''){
    : if (islower(*sPtr)) [b][color=Red]--> ; <-- THIS ONE![/color][/b] {
    : *sPtr=toupper(*sPtr);
    : }
    : ++sPtr;
    : getch();
    : }
    : }
    : [/code]
    : [u][color=Red][b]OUTPUT[/b][/color][/u]
    :
    : the string before conversion is: cdfg
    : puka
    :
    [color=Blue][/color]
  • I did what you said and theres 0 warnings,errors. But the output didnt change.
    i.e the string didnt change into uppercase.

    for my understanding the islower function and the isupper function is not working.
    what could be the reason??? is the ctype.h file not called properly or smthing??

    thank you
  • This post has been deleted.
  • This post has been deleted.
  • : I did what you said and theres 0 warnings,errors. But the output
    : didnt change.
    : i.e the string didnt change into uppercase.
    :
    : for my understanding the islower function and the isupper function
    : is not working.
    : what could be the reason??? is the ctype.h file not called properly
    : or smthing??
    :
    : thank you
    :
    [color=Blue]The problem is call to getch() - look closely and you will see that this line is INSIDE the while() loop. Move that line OUTSIDE of while, because it will require for every converted character to press a key to move to next character in a loop. If you run the program now and simply press any key 4 times (that is how manu characters you trying to convert) - you should see the result AFTER loop ends.[/color]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories