函数:
gets(),puts(),strcat()
strncat(),strcmp(),strncmp()
strcpy(),strncpy()
sprintf(),strchr()
先看gets()和puts()函数吧。
/*************************************************************************************** * File Name : main.c * Copyright : 2011-2012 ecjtu Corporation,All Rights Reserved * Module Name : 字符串 * * CPU : PC * RTOS : None * Create Date : 2012/1/04 * Author/Corporation : 惊涛骇浪/ecjtu * * Abstract Description : 打印信息 *---------------------------Revision History-------------------------------- * Revision History * No. Version Date Revised by Item Description * 1 V0.95 11.12.02 惊涛骇浪 打印信息 ***************************************************************************************/ #include<stdio.h> #define MSG "You must have many talents, Tell me some." #define LIM 4 #define LINELEN 81 /*************************************************************************************** * Function Name : Main() * Create Date : 2011/12/10 * Author/Corporation : 涛行天下 * * Description : Find a proper thread in thread array * * Param : ThreadNo : someParam description ThreadStaus : someParam description * * * Global Variable : DISP_wuiSegmentAppID * File Static Variable : naucThreadNo * Function Static Variable : None * *---------------------------------------------------- * Revision History * No. Date Revised by Item Description * V0.0 2011/12/10 涛行天下 ... .... ***************************************************************************************/ int main(void) { char name[LINELEN]; char talents[LINELEN]; int i; const char m1[40] = "Limit yourself to one line's worth."; const char m2[] = "If you can't think of anything,fake it"; const char *m3 = "\nEnough about me - what's your name?"; const char *mytal[LIM] = { "Adding numbers swiftly", "Multiplying accurately", "Following instructions to the letter", "Understanding the C languge" }; printf("Hi I'm Clyde the Computer,"" I have many talents.\n"); printf("Let me tell you some of them.\n"); puts("What were they?Ah,yes, here's a partial list."); for(i = 0; i < LIM; i++) { puts(mytal[i]); } puts(m3); gets(name); printf("Well, %s, %s\n",name,MSG); printf("%s\n%s\n",m1, m2); gets(talents); puts("Let's see if I've got that list: "); puts(talents); printf("Thanks for the information,%s, \n",name); return 0; }
下面再看看还有一些情况要注意的:
char greeting[50] = "Hello, and" "how are" "you" "today!"; 这句就是ANSI C会将其串联起来
还有就是想要输出“的话那么就使用\这个符号
再看一个把字符串看做指针
#include<stdio.h> int main(void) {
/*%s格式将输出字符串We,%p格式产生一个地址。*/ printf("%s, %p, %c\n", "We","are", *"space farers");
/*这里主要是*后面的那些字符串当做指针,那个就是指向字符串的第一字母,也就是代表第一个字母的地址然后就是取内容了*/ return 0; }