/*
3.设计并测试一个函数,从一行输入中把一个单词读入一个数组中,并丢弃输入行中的其余字符。
该函数应该跳过第1个非空白字符前面的所有空白。将一个单词定义为没有空白、制表符或换行符的字符序列。
4.设计并测试一个函数,它类似编程练习3的描述,只不过它接受第2个参数指明可读取的最大字符数。
#include<stdio.h>
#define SIZE 40
void in_word(char str[]);
int main(void)
{
char store[SIZE];
in_word(store);
fputs(store, stdout);
return 0;
}
void in_word(char str[])
{
printf("请输入一个单词:\n");
scanf("%s", str);
printf("您输入的单词是:\n");
}
*/
#include<stdio.h>
#define SIZE 40
void in_word(char str[],int n);
int main(void)
{
char store[SIZE];
in_word(store, 5);
fputs(store, stdout);
return 0;
}
void in_word(char str[], int n)
{
int i = 0;
while ((str[i] = getchar()) && i < n)
if (str[i] != ' ' && str[i] != '\n' && str[i] != '\t')
i++;
str[i] = '\0';
}
C PRIMER PLUS(第六版编程练习)11.13编程练习_4题
本文介绍了C Primer Plus第六版中的11.13编程练习,深入探讨C语言的编程技巧和概念,通过实际编程例子帮助读者巩固知识。

被折叠的 条评论
为什么被折叠?



