字符和字符串的区别?
字符就是单个字符,字符串就是多个字符的集合
另外,单个空白字符和空白字符串是两个概念, 在c中字符就是单个字符, 字符串是用\0结尾的,字符和字符串在操作上也不同,复制等等是不一样的
#include <stdio.h>
void put1(const char * string) /* string not altered */
{
while (*string != '\0') /*可以while(*string),当*string为0将结束循环*/
putchar(*string++);
}
#include<stdio.h>
#include<string.h>
void fit(char *,unsigned int);
int main(void)
{
char mesg[81];
gets(mesg);
fit(mesg,8);
puts(mesg);
puts("Let's see some more of the string.");
puts(mesg+10);
return 0;
}
void fit(char *string,unsigned int size)
{
if(strlen(string)>size)
*(string+size)='\0';
}
size_t:无符号程序变量,相当unsigned int ,举例说明:
size_t size=sizeof(string);
unsigned int size=sizeof(string);