C语言中怎么判定输入是否为空

来源:百度知道 编辑:UC知道 时间:2024/07/08 11:00:36
原题如下
Calculate a + b

Input
The input will consist of a series of pairs of integers a and b,separated by a space, one pair of integers per line.

Output
For each pair of input integers a and b you should output the sum of a and b in one line,and with one line of output for each line in input.

Sample Input
1 5

Sample Output
6

Hint:

Q:Where is the input and the output?
A:Your program shall read input from stdin('Standard Input') and write output to stdout('Standard Output').For example,you can use 'scanf' in C or 'cin' in C++ to read from stdin,and use 'printf' in C or 'cout' in C++ to write to stdout.
User programs are not allowed to open and read from/write to files, you will get a "Runtime Error" if you try to do so.
不行...提交了答案还是提示Runtime Error

ACM吧

#include <iostream>
#incldue <cstdlib>
using namespace std;

int main()
{
int a,b;
while(cin>>a>>b)
cout<<a+b<<endl;

}

就行了

或者while里改成
while((scanf(%d %d,&a,&b))!=EOF)

scanf()里规定了输入两个数之间是空格

而用cin可以不用管 c++的io流很强大 不需要做这种考虑
但是scanf明显比cin快

1.使用strlen函数来判断输入是否为空,如果返回值为0,就是空。
  strlen做的是一个计数器的工作,它从内存的某个位置(可以是字符串开头,中间某个位置,甚至是某个不确定的内存区域)开始扫描,直到碰到第一个字符串结束符'\0'为止,然后返回计数器值(长度不包含“\0”)。
原  型:extern unsigned int strlen(char *s);
头文件:string.h
格  式:strlen (字符数组名)
功  能:计算字符串s的(unsigned int型)长度,不包括'\0'在内
说  明:返回s的长度,不包括结束符NULL。

2.例程:

#include <stdio.h>
#include <string.h>
int main(){
    char s[1000];
    while (gets(