简体   繁体   English

在C上读取空格

[英]Reading spaces on C

I'm trying to read a serie of characters like the following one in C: 我正在尝试读取一系列字符,例如C中的以下字符:

   &&&&&&&&\n& & &    &\n& & &&&& &\n

(notice that in the beginning there are spaces too). (请注意,开头也有空格)。

I'm using a cicle "while" with: 我正在使用cicle“ while”与:

scanf("%c",&cvar);

because I'm "storing" the characters into an array of structs that i'm using. 因为我将字符“存储”到我正在使用的结构数组中。

However, the program keeps ignoring the first spaces, and only starts storing from the first '&' appearence. 但是,该程序一直忽略第一个空格,仅从第一个“&”出现开始存储。

Any tips? 有小费吗? Thank you in advance and sorry for my poor english. 在此先感谢您,我的英语不好。

Here is part of the code: 这是代码的一部分:

while(scanf("%c",&lab[i].simb)!=EOF){
    lab[i].x=x;
    lab[i].y=y;
    if(lab[i].simb=='\n'){
        x=0;
        y++;            
    } else x++;
    i++;
}

Read this... 读这个...

I'll suggest to use getline if you are using gcc , but if however you want to read each character use getc instead of scanf ... and sorry for my poor English too... 如果您使用的是gcc ,我建议您使用getline ,但是如果您想读取每个字符,请使用getc而不是scanf ...并对我的英语不好也感到抱歉...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM