雅静

8基础七:一些函数(菜鸟编程教学7)

文档

0.8

已售 0
194.41KB

数据标识:D17207965841780546

发布时间:2024/07/12

卖家暂未授权典枢平台对该文件进行数据验证,您可以向卖家

申请验证报告

数据描述

目录
Content
Chapter_1
Chapter_1
通过以前的讲解,以后我们讲解的东西应该就进入一种直接上程序少讲解,让大家自己去调试研究,然后我们会介绍linux系统的编程问题,如果有网我会加一些图片,等我们c基础学完我就开始讲解汇编知识,慢慢让大家深入底层了解系统底层,硬件底层好比你会用路由器是一种能力,那么,如果你会造路由器相信你会提高更多!深入浅出的过程我相信大家会成功的!话不多说,今天我们来了解一个简单的循环,大家都应该知道见过,我就不多啰嗦了,直接给出程序
很多函数都包含在头文件中,需要调用时候我们拿出来用就可以了,这里我们先说一下string.h的一些基本用法:
#include
#include
#include
//#define null 0
void first_Array()
{
char str1[300],str2[200],str3[100];
int x;
printf("\n==>请输入第一串字符:");
gets(str1);//use gets to get the string!
printf("\n==>请输入第二串字符:");
gets(str2);
printf("\n==>请输入第三串字符:");
gets(str3);
printf("\n\t下面您将看到的是第一串字符的输出!\n");
puts(str1);//use puts to put the string on the screen!
_sleep (3000);
printf("\n\t下面您将看到的是第二和第三串数组的链接!\n");
strcat(str2,str3);//use strcat to link the strings!
printf("%s",str2);//string must save on the first string!
/*so the first string must be bigger then second string!*/
_sleep (3000);
printf("\n\t下面您将看到的是第一串字符的长度!\n");
x = strlen(str1);//use the strlen to check the string's length!
/*this function is not include '/0',so if(*=='/0') then endof!*/
printf("%d",x);
_sleep (5000);
printf("\a");
}
void second_Array()
{
char str[300],str4[10],str5[]={"china"};
printf("\n==>请输入一串含有大写和小写的字符串:");
gets(str);
printf("\n\t所有字符全部转换成为大写!\n");
printf("%s",strupr(str));
//use this function to change the string to big world!
_sleep (3000);
printf("\n\t所有字符全部转换成为小写!\n");
printf("%s",strlwr(str));
//use this function to change the string to small world!
_sleep (3000);
printf("\n\t先进行输出一个已经定义的字符串!\n");
puts(str4);
_sleep (3000);
printf("\n\t下面将字符串进行复制!\n");
strcpy(str4,str5);
//use strcpy to copy the second string to the first string
puts(str4);
_sleep (3000);
printf("\n\t另外一种拷贝方式!\n");
strcpy(str4,"LOVE");//another method to copy the string!
puts(str4);
_sleep (3000);
printf("\n\t我们可以把字符串进行分离!\n");
printf("%c\t%c\t%c\t%c",str4[0],str4[1],str4[2],str4[3]);
_sleep (3000);
printf("\n\t我们可以复制任意字符串并且组合!\n");
strncpy(str4,str5,2);//use strncpy to copy second string to first string
/*now you must to know this copy will save on the str4[0],str4[1], */
/*but str4[2] and str4[3] is not changed,*/
/*and the first string must have more space to save the second string!*/
puts(str4);
_sleep (5000);
printf("\a");
}
void third_Array()
{
char str6[50],str7[50];
printf("\n\t下面将进行字符的比较!\n");
printf("\n==>请输入第一串字符:");
gets(str6);
printf("\n==>请输入第二串字符:");
gets(str7);
printf("\n\t下面将输出两串字符的比较结果!\n");
printf("\n如果返回为0则str1=str2返回为正则str1>str2返回为负则str1printf("%d",strcmp(str6,str7));//use strcmp to check two strings!
_sleep (3000);
printf("\n\t我们还可以这样进行比较!\n");
printf("china cp China=%d\n",strcmp("china","China"));
printf("China cp china=%d\n",strcmp("China","china"));
printf("china cp China=%d\n",strcmp("china","china"));
_sleep (3000);
//so,we must use this function to check the code number such as:
char str_1[50],str_2[8]={"+-*/*-+"};
printf("请输入密码:");
gets(str_1);
if(strcmp(str_1,str_2))
printf("ERROR!\n");
else
printf("OK!\n");
printf("\a");
}
int main()
{
first_Array();
second_Array();
third_Array();
printf("\n按回车键结束程序\n");
getchar();
return 0;
}
//其中我加了一些英文注释,由于是GCC编译器,我就干脆加一些英文注释吧,有英语语法错误的地方请多多谅解!这个是关于string.h的用法,程序里面我已经说的很清楚了,在这就不再啰嗦了
然后我们说一下ctype中的一些简单用法,这里只做简单了解,因为ctype,ftype这个需要专门讲解!
//这是输出ascii值的一种方法,其中ctype可以精确的求出127以内的值,否则不予输出我们调用_ctype来做这点
#include
#include
int main (void)
{
int ascii_char;
for (ascii_char = 0; ascii_char < 128; ascii_char++)
if (isprint(ascii_char))
printf("ASCII value %d setting (hex) %x ASCII %c\n",
ascii_char, _ctype[ascii_char], ascii_char);
else
printf("ASCII value %d setting (hex) %x ASCII %c\n",
ascii_char, _ctype[ascii_char], ascii_char);
getchar();
return 0;
}
//记得我们可以通过数组的方法来转换大小写,这里我们利用ctype函数也可以做到这点引用tolower与toupper函数。
#include
#include
#include
main()
{
char str[500],array[500];
int i;
printf("\n请输入一串含有大小写的字符串:");
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
array[i]=tolower(str[i]);
printf("\n==>转换小写后您的输入为: %s\n",array);
_sleep (2000);
for(i=0;str[i]!='\0';i++)
array[i] = toupper(str[i]);
printf("\n==>转换大写后您的输入为: %s\n",array);
_sleep (5000);
}
最后我浅析一下system函数,这个本身是用于linux程序下面的,通过system来做系统调用,在这里我们需要包含头文件
举个最简单的例子
system("ls -al");
这样我们就列举出了当前文件夹下的文件以及文件夹的具体参数,注意,有些输出需要加一些符号
比如我们在引号中输入"\"这个反斜杠我们需要加上\\才能输出,也就是双反斜杠才可以输出反斜杠
其次我们需要输出特殊符号,比如输出">",这个符号我们不能直接写在system("");引号这里,而是我们需要写上"^>"来输出一个">"符号!
这一节我们就讲到这里!
data icon
8基础七:一些函数(菜鸟编程教学7)
0.8
已售 0
194.41KB
申请报告