簡體   English   中英

讀取 C 中帶空格的行 編程和分割單詞

[英]Reading line with spaces in C Programming and segmentating the words

我有類似於以下的輸入:

約翰希 ID5 409-208

我需要能夠讀取輸入並在如下結構上組織 output:

姓名:強希
類型:ID5
身份證號碼:409-208

但我正在努力尋找有關如何使用空格處理片段的文獻。 我承認,我對 C 很陌生。

聲明具有適當長度的變量,並且:

scanf("%s %s %s", name, type, id);

這是你想要的那種東西嗎?

#include <stdio.h>
#include <string.h>

int main()
{
    char mstring[] = "Hello World";
    char space = ' ';
    int a = 0;
    
    while ( a < strlen(mstring))
    {
        if (mstring[a] == space)
        {
            printf ("found space!");
        }
        a++;
    }

    return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM