[英]what is the replacement of “ for line in sys.stdin: ” in C?
我被要求將python程序轉換為C程序.python程序包含我無法轉換的loop語句。
for line in sys.stdin:
<Some Code>
我正在尋找CI替代它,以為以下代碼可能有效,但我對此表示懷疑。
char A[100]
while(1)
A=gets();
盡量詳細。
我第二次約阿希姆的回答:
char A[100]; /* Your code misses the semicolon here. */
while(fgets(A, sizeof A, stdin) != NULL)
{
/* process A here */
}
請注意,這僅限於100個字符的行長,Python代碼也不受這種限制。
如果有,請改用getline()
,它沒有長度限制。
有很多選擇供您選擇:
int fgetc(FILE *stream)
char *fgets(char *s,int n,FILE *stream)
int getc(FILE *stream)
size_t fread(void *ptr,size_t size,size_t nobj,FILE *stream)
您不能使用僅提供的代碼:
1.code from python means get from stdin
2.with no limits of 100 characters.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.