如何在char字符串之前扫描空字符串 [英] How do I scan a blank string before a char string

查看:80
本文介绍了如何在char字符串之前扫描空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在字符串之前扫描一个空白字符串....但我无法做到这一点



输入

2



abc



预期产量 < br $> b $ b

abc



实际输出

abc

abc



以下我给了我的代码.....



i也尝试了 fgets ,但它显示了与获取案例相同的结果



什么我试过了:



i want to scan a blank string before a char string....but im unable to do that

input
2

abc

expected output

abc

actual output
abc
abc

below i have given my code.....

i have tried fgets too but it shows the same result as in gets case

What I have tried:

#include <stdio.h>
#include <string.h>
int main() 
{
  char s[10000]; 
    int t;
    scanf("%d\n",&t);
   while(t>0)
     {   
         
         gets(s);
         puts(s);
       
      t--;  
     }
	
	return 0;
}

推荐答案

在puts(s)行后面添加以下行:





s [0] = 0;
Just add the following line right after the puts( s ) line:


s[0] = 0;


这篇关于如何在char字符串之前扫描空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆