请问C语言中的这些语句gets,fgets,puts,sprintf,strcpy,strcat,strcmp,strlen的语义和用法是什么?

我是要考计算机三级,但是对C一点也不懂,所以谢谢哪位高手了。。

gets  【1】函数:gets
  【2】头文件:stdio.h
  【3】功能:从stdin流中读取字符串,直至接受到换行符或EOF时停止,并将读取的结果存放在str指针所指向的字符数组中。换行符不作为读取串的内容,读取的换行符被转换为null值,并由此来结束字符串。
  【4】注意:本函数可以无限读取,不会判断上限,所以程序员应该确保str的空间足够大,以便在执行读操作时不发生溢出。
  【5】示例:
  #include"stdio.h"
  void main()
  {
  char str1[5];
  gets(str1);
  printf("%s\n",str1);
  }
fgets  函数名: fgets
  功 能: 从流中读取一字符串
  用 法: char *fgets(char *string, int n, FILE *stream);
  形参注释:*string结果数据的首地址;n-1:一次读入数据块的长度,其默认值为1k,即1024;stream文件指针
  序 例:
  #include <string.h>
  #include <stdio.h>
  int main(void)
  {
  FILE *stream;
  char string[] = "This is a test";
  char msg[20];
  /* open a file for update */
  stream = fopen("DUMMY.FIL", "w+");
  /* write a string into the file */
  fwrite(string, strlen(string), 1, stream);
  /* seek to the start of the file */
  fseek(stream, 0, SEEK_SET);
  /* read a string from the file */
  fgets(msg, strlen(string)+1, stream);
  /* display the string */
  printf("%s", msg);
  fclose(stream);
  return 0;
  }
  fgets函数用来从文件中读入字符串。fgets函数的调用形式如下:fgets(str,n,fp);此处,fp是文件指针;str是存放在字符串的起始地址;n是一个int类型变量。函数的功能是从fp所指文件中读入n-1个字符放入str为起始地址的空间内;如果在未读满n-1个字符之时,已读到一个换行符或一个EOF(文件结束标志),则结束本次读操作,读入的字符串中最后包含读到的换行符。因此,确切地说,调用fgets函数时,最多只能读入n-1个字符。读入结束后,系统将自动在最后加'\0',并以str作为函数值返回。
puts  功 能: 送一字符串到流中
  用 法: int puts(char *string);
  程序例:
  #include <stdio.h>
  int main(void)
  {
  char string[] = "This is an example output string\n";
  puts(string);
  return 0;
  }
  初学者要注意以下例子
  #include <stdio.h>
  #include <conio.h>
  int main(void)
  {
  int i;
  char string[20];
  for(i=0;i<10;i++)
  string='a';
  puts(string);
  getch();
  return 0;
  }
  从此例中可看到puts输出字符串时要遇到'\0’也就是字符结束符才停止。如上面的程序加上一句 string[10]='\0';
  #include <stdio.h>
  #include <conio.h>
  int main(void)
  {
  int i;
  char string[20];
  for(i=0;i<10;i++)
  string='a';
  string[10]='\0';
  puts(string);
  getch();
  return 0;
  }
  运行就正确了
  此 外 puts 和 printf 的用法一样
==~~~
温馨提示:答案为网友推荐,仅供参考
相似回答