C语言宽字符 30

/*查找一个字符串是否出现在另一个字符串中(忽略大小写)*/#include<stdio.h>#include<string.h>#include<ctype.h>int... /* 查找一个字符串是否出现在另一个字符串中(忽略大小写) */
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
char text[100];
char substring[40];
int i;

printf("\nEnter the string to be searched(less than 100 characters):\n");
fgets(text, sizeof(text), stdin); /*输入要搜索的字符串*/

printf("\nEnter the string sought (less than 40 characters ):\n");
fgets(substring, sizeof(substring), stdin);/*输入子字符串*/

text[strlen(text)-1] = '\0'; /* 覆盖在每个字符串的换行符 */
substring[strlen(substring)-1] = '\0';

printf("\nFirst string entered:\n%s\n", text);
printf("\nSecond string entered:\n%s\n", substring);

for(i=0;(text[i]=toupper(text[i]))!='\0';i++); /*字符串都转换为大写*/
for(i=0;(substring[i]=toupper(substring[i]))!='\0';i++);

printf("\nThe second string %s found in the first.",
((strstr(text, substring) == NULL) ? "was not" : "was"));
getch();
return 0;
}
宽字符代码如下:
#include <stdio.h>
#include <wchar.h>

int main(void)
{
wchar_t text[100];
wchar_t substring[40];
int i;

printf("\nEnter the string to be searched(less than 100 characters):\n");
fgetws(text, 100, stdin);
printf("\nEnter the string sought (less than 40 characters ):\n");
fgetws(substring, 40, stdin);

text[wcslen(text)-1] = L'\0';
substring[wcslen(substring)-1] = L'\0';

printf("\nFirst string entered:\n%S\n", text);
printf("\nSecond string entered:\n%S\n", substring);

for(int i = 0 ; (text[i] = towupper(text[i]))!='\0' ; i++);
for(int i = 0 ; (substring[i] = towupper(substring[i]))!='\0' ; i++);

printf("\nThe second string %s found in the first.",
((wcsstr(text, substring) == NULL) ? "was not" : "was"));
getch();
return 0;
}
第一个程序可以运行,第二个不能。两个程序都是从书里面抄来的,我用的是wintc191
编译器,这个编译器如何使用宽字符?
展开
 我来答
陈学阳
2010-09-18 · TA获得超过2.8万个赞
知道大有可为答主
回答量:2.1万
采纳率:14%
帮助的人:5976万
展开全部
宽字符就是UNICODE操作的函数和ASIC字符有一点区别,一般用来表示汉字,MFC里面用_T("")表示宽字符和ASIC字符兼容的字符串,就是通过宏定义来完成的,如果定义了使用UNICODE,_T("")宏就将其中的字符串转换成UNICODE 否则就是普通的ASIC字符,建议写MFC程序是定义字符串使用_T("字符串")的形式。

如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式