
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
编译器,这个编译器如何使用宽字符? 展开
#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
编译器,这个编译器如何使用宽字符? 展开
1个回答
展开全部
宽字符就是UNICODE操作的函数和ASIC字符有一点区别,一般用来表示汉字,MFC里面用_T("")表示宽字符和ASIC字符兼容的字符串,就是通过宏定义来完成的,如果定义了使用UNICODE,_T("")宏就将其中的字符串转换成UNICODE 否则就是普通的ASIC字符,建议写MFC程序是定义字符串使用_T("字符串")的形式。
如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!
如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询