小文字の文を大文字に変換するプログラムを書いています。紐の長さも欲しいです。私は(両方の)配列とポインタでそれをやっています。プログラムは次のとおりです。
/* Program to convert the lower case sentence in upper case sentence and also calculate the length of the string */
#include<stdio.h>
main()
{
char fac='a'-'A',ch[20],*ptr,a[20];int i=0,count=0;
ptr=ch;
/* Changing case and printing length by using pointers */
printf("Enter the required string");
gets(ptr);
while(*ptr!='\0')
{
*ptr+=fac; // LINE #1
ptr++;
count++;
}
puts(ptr);
printf("%d",count);
/* Changing case by using arrays */
printf("Enter the required string");
gets(ch);
while(ch[i]!='\0')
{
ch[i]+=fac;
i++;
}
puts(ch);
return 0;
}
このプログラムは、長さの出力 (ポインター部分) と大文字と小文字の変更 (配列部分) で完全に機能します。問題は、ポインターによる大文字と小文字の変換です。LINE#1 は、ポインター「ptr」に格納されている値を必要な数 ( 32 ) だけインクリメントするという印象を受けています。しかし、画面には何も起こっていません。なぜこうなった?助けてください。