B
bpascal123
Hi,
I'm posting quite a lot, i'm learning c without any solid programming
experience. So when my code doesn't work after looking why if i can't
get to know why, I ask here and i keep on coding as well.
So below is a simple lowercase to uppercase code from a to z that
doesn't fully work. I use gcc on linux and i've tried on gcc on
Windows and the output is quite the same (however nothing is return in
djgpp windows).
In gcc linux, It takes the input but it returns it after some delay
and it adds some characters i have never seen at this stage of
learning and nowwhere since i use a computer...
I don't know if it's the right way to do this, i wish pointers
wouldn't be involved for this. I can't think of a way to do this with
functions to split actions. Once this part below works, i'd like to
add some more string functions on the model of the function (UppStrg)
below :
#include <stdio.h>
#include <string.h>
void UppStrg(char *Low, char *Upp, int cnt) ;
int main(void)
{
int n = 40 ;
char Txt1[n] ;
char Txt2[n] ;
int i ;
printf("\n\nThis program reads and converts : 1- a lower case string
into upper case : \n") ;
do
{
printf("\nEnter a lowercase string : \n") ;
scanf("%s", Txt1) ;
n = strlen(Txt1) ;
for ( i = 0 ; i <= n ; i++ )
{
if ( (Txt1 <= 'a' ) || (Txt1 >= 'z') ) /* IF checks if there
are any characters other than lowercase letters */
printf("\nThere are no lowercase letters in this string !\n\n") ;
else
UppStrg(&Txt1, &Txt2, n) ;
}
} while ( (Txt1 <= 97 ) && (Txt1 >= 123) ) ;
for ( i = 0 ; i <= n ; i++ )
putchar(Txt2) ;
printf("\n\n") ;
return 0 ;
}
/* Function that should move a lowercase letter into uppercase */
void UppStrg(char *Low, char *Upp, int cnt)
{
int i ;
for ( i = 0 ; i <= cnt ; cnt++ )
*(Upp+i) = *(Low+i) - 'a' + 'A';
}
I'm posting quite a lot, i'm learning c without any solid programming
experience. So when my code doesn't work after looking why if i can't
get to know why, I ask here and i keep on coding as well.
So below is a simple lowercase to uppercase code from a to z that
doesn't fully work. I use gcc on linux and i've tried on gcc on
Windows and the output is quite the same (however nothing is return in
djgpp windows).
In gcc linux, It takes the input but it returns it after some delay
and it adds some characters i have never seen at this stage of
learning and nowwhere since i use a computer...
I don't know if it's the right way to do this, i wish pointers
wouldn't be involved for this. I can't think of a way to do this with
functions to split actions. Once this part below works, i'd like to
add some more string functions on the model of the function (UppStrg)
below :
#include <stdio.h>
#include <string.h>
void UppStrg(char *Low, char *Upp, int cnt) ;
int main(void)
{
int n = 40 ;
char Txt1[n] ;
char Txt2[n] ;
int i ;
printf("\n\nThis program reads and converts : 1- a lower case string
into upper case : \n") ;
do
{
printf("\nEnter a lowercase string : \n") ;
scanf("%s", Txt1) ;
n = strlen(Txt1) ;
for ( i = 0 ; i <= n ; i++ )
{
if ( (Txt1 <= 'a' ) || (Txt1 >= 'z') ) /* IF checks if there
are any characters other than lowercase letters */
printf("\nThere are no lowercase letters in this string !\n\n") ;
else
UppStrg(&Txt1, &Txt2, n) ;
}
} while ( (Txt1 <= 97 ) && (Txt1 >= 123) ) ;
for ( i = 0 ; i <= n ; i++ )
putchar(Txt2) ;
printf("\n\n") ;
return 0 ;
}
/* Function that should move a lowercase letter into uppercase */
void UppStrg(char *Low, char *Upp, int cnt)
{
int i ;
for ( i = 0 ; i <= cnt ; cnt++ )
*(Upp+i) = *(Low+i) - 'a' + 'A';
}