大家看看这个C程序的错误在哪

来源:百度知道 编辑:UC知道 时间:2024/05/21 14:21:07
给定程序MODI1.C中 fun 函数的功能是:分别统计字符串中大写字母和小写字母的个数。
例如, 给字符串 s 输入:AAaaBBb123CCccccd,则应输出结果:upper =
6, lower = 8。
以下是源码:
#include <conio.h>
#include <stdio.h>
void NONO(void);

void fun ( char *s, int *a, int *b )
{
int i=0;
for(;i<100;i++)
{
if ( *(s+i) >= 'A' && *(s+i) <= 'Z' ) //这里有错吗?
(*a)++;
if ( *(s+i) >= 'a' && *(s+i) <= 'z' )
(*b)++;

}
}

void main( )
{
char s[100];
int upper = 0, lower = 0 ;
clrscr();
printf( "\nPlease a string : " );
gets ( s );
fun ( s, & upper, &lower );
printf( "\n upper = %d lower = %d\n", upper, lower );
NONO( );
system("pause");
}
void NONO(void)
{
int i, upper, lower ;
char s[100] ;
FILE *rf, *wf;
rf = fopen(

#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
void NONO(void);

void fun ( char *s, int *a, int *b )
{
int i=0;
for(;i<s[i]!='\0';i++)//这里错了,不能一直到100
{
if ( *(s+i) >= 'A' && *(s+i) <= 'Z' ) //这里有错吗->没错
(*a)++;
if ( *(s+i) >= 'a' && *(s+i) <= 'z' )
(*b)++;

}
}

void main( )
{
char s[100];
int upper = 0, lower = 0 ;
//clrscr();
printf( "\nPlease a string : " );
gets ( s );
fun ( s, & upper, &lower );
printf( "\n upper = %d lower = %d\n", upper, lower );
//NONO( );
system("pause");
}
void NONO(void)
{
int i, upper, lower ;
char s[100] ;
FILE *rf, *wf;
rf = fopen("in.dat", "r") ;
wf = fopen("out.dat", "w");