#29426: 為什麼會Segmentation Fault


110703046@g.nccu.edu.tw (hys)

學校 : 不指定學校
編號 : 178973
來源 : [118.150.147.45]
最後登入時間 :
2022-03-22 00:58:45
a011. 00494 - Kindergarten Counting Game -- UVa494 | From: [118.150.147.45] | 發表日期 : 2022-02-28 14:42

Segmentation fault到底怎麼解TAT

 

#include<stdio.h>

#include<ctype.h>

char arr[10000];

int main(void)

{

  while(getline(arr)!=EOF){

    int n=0;

    int space=0;

    while(arr[n]!='\0'){

      if(isspace(arr[n]))space++;

      arr[n]=0;

      n++;

    }

    printf("%d\n", space+1);

  }

  return 0;

}

 
#29428: Re:為什麼會Segmentation Fault


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
a011. 00494 - Kindergarten Counting Game -- UVa494 | From: [27.52.76.229] | 發表日期 : 2022-02-28 16:27

  while(getline(arr)!=EOF){


getline()是什麼函式?我沒用過,編譯時產生錯誤訊息 too few arguments to function call, expected 3, have 1,我網路上查到的getline確實需要三個參數:https://en.cppreference.com/w/c/experimental/dynamic/getline

 
ZeroJudge Forum