主文件
#include <iostream>
#include "Module2.h"
int main()
{
std::cout<<"This is a test of Module2.h"<<std::endl;
std::cout<<UCase("This is a test of UCase")<<std::endl;
std::cout<<LCase("This is a test of LCase")<<std::endl;
system("pause");
return 0;
}
模块2.h
#include <iostream>
#include "Module2.h"
int main()
{
std::cout<<"This is a test of Module2.h"<<std::endl;
std::cout<<UCase("This is a test of UCase")<<std::endl;
std::cout<<LCase("This is a test of LCase")<<std::endl;
system("pause");
return 0;
}
模块2.cpp
///////////////////////////////////////////////////
//Module : Module2.cpp
//
//Purpose : Shows the usage of modular functions
///////////////////////////////////////////////////
#include "Module2.h"
///////////////////////////////////////////////////
//UCase()
char *UCase(char *str)
{
//convert each char in the string to uppercase
//
int len = strlen(str);
for ( int i ; i < len ; i++)
{
std::cout<<"In UCase"<<std::endl;
str[i]=toupper(str[i]);
}
return str;
}
///////////////////////////////////////////////////
//LCase()
char *LCase(char *str)
{
//convert each char in the string to uppercase
//
int len = strlen(str);
for ( int i ; i < len ; i++)
{
std::cout<<"In LCase"<<std::endl;
str[i]=tolower(str[i]);
}
return str;
}
当我运行它时,没有警告或错误。但是,它不会上下字符串。我认为我的 for 循环是错误的,但它似乎是正确的。我的代码有什么问题。