fgets

    1熱度

    1回答

    我想製作一個只接受來自用戶的小寫字符的程序。 而且我希望它在打印錯誤時,只要有空格,輸入中的大寫字母或字母旁邊的任何字符。 但我的代碼表現出意想不到的方式,我不知道爲什麼。 僅當輸入中輸入的第一個字符是空格或大寫字母時,纔會打印錯誤消息。即使我正在用fgetc掃描整個字符串尋找一個空白字符,它又有什麼可能? #include <stdio.h> #include <stdlib.h> #inc

    -5熱度

    1回答

    我想通過stdin讀取一個字符串,所以我選擇了fgets。但是我得到了這個警告:初始化從指針中取得整數而沒有強制轉換。 這裏是我的代碼: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stddef.h> #define MAX_LINIA 301 int main(int argc,char

    0熱度

    1回答

    我必須編寫一個程序,讀取學生姓名和ID列表,並根據名字,姓氏和ID對它們進行排序。但目前我的代碼有兩個問題。 #include <stdio.h> int main() { char firstName[200][21], lastName[200][51]; unsigned short id[200]; // used short to decrease memory

    -1熱度

    1回答

    這是我的函數的代碼: char str[DIM_STR]; char tipo[DIM_TIPO]; int j=0, var=0; for(j=0; j<DIM_STR; j++) str[j]='\0'; for(j=0; j<DIM_TIPO; j++) tipo[j]='\0'; while(fgets(str, DIM_STR, fp)!=NULL)

    0熱度

    2回答

    這是我的代碼。我不知道爲什麼我沒有在頁面上找到任何東西。建議我一種模式,如果我想每次運行我的代碼,它應該在最後附加。我也應該能夠你使用了錯誤的模式fopen從中 <?php $a=fopen("Welcome.txt","a+"); fwrite($a, "abc"); echo fgets($a); fclose($a); ?>

    -1熱度

    1回答

    該程序不會編譯fgets的teste1函數。或者至少它不能正常工作,它不會讓我輸入字符串,程序會在打印出「Nome do cliente」後立即結束。 如果我禁用其他scanf的功能,它將運行沒有任何問題。 如何讓fgets工作? #include <stdio.h> void teste1(){ char teste[50]; printf("Nome do cliente

    1熱度

    1回答

    void menu() { int op; printf("\n Choose a option from below : \n\n"); printf(" 1: Add Contact\n" " 2: View A Contact\n" " 3: View All Contacts\n" " 4: View All Cont

    2熱度

    2回答

    的Apple developer documentation狀態: 爲fgets安全注意:雖然fgets功能提供了讀取數據的數量有限的能力,就必須使用時要小心。像「更安全」列中的其他功能一樣,fgets始終終止字符串。但是,與該列中的其他函數不同,它需要讀取的最大字節數,而不是緩衝區大小。 最後一句對我來說聽起來不對。爲了比較,這裏是what POSIX says: 的fgets()功能必須從閱讀

    1熱度

    2回答

    您好考慮下面的簡單的程序: int main(void) { //exercise 1 float num2; printf("please enter a number \n"); scanf_s("%f", &num2); printf("the number multiple by 3 is %3.3f\n", num2 * 3);

    1熱度

    1回答

    錯過我有以下代碼:(cpp14) static int const max_len = 1000; FILE* m_in_log = NULL; FILE* m_log = NULL; ... ... bool readLine(char* line, int max_len) if(!fgets(line, max_len, m_in_log)) { ret