我正在尝试使用mvprintw从数组中打印出单词。但是,无论我尝试什么,mvprintw似乎都无法正常工作。
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAX_WORD_LENGTH 12 /* The maximum length a word can be. */
#define MAX_WORDS 75 /* The maximum words that can be in the DS4Talker. */
void trim_whitespace(char *string);
int read_words(char *word_list[MAX_WORDS], char *file_name);
// Compile with gcc lab09.c -o lab09 -lncurses
// Run with ./ds4rd.exe -d 054c:05c4 -D DS4_BT -t -b -bt -bd | ./lab09 word_list.txt
/*----------------------------------------------------------------------------
- Implementation -
-----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
char *word_list[MAX_WORDS];
int word_count = read_words(word_list, argv[1]);
int i = 0; int row = 1; int col = 1;
initscr();
for(int c = 0; c < word_count; c++){
mvprintw(col, row, "%15s\n", word_list[c]);
if(c % 15 == 0) {
row++;
col++;
}
printf("This is doing nothing :D\n");
}
//fclose(fptr);
refresh();
endwin();
return 0;
}
* @param string - The string to ensure has no whitespace.
*/
void trim_whitespace(char *string)
{
int length = strlen(string);
if (length == 0) return;
int i = length - 1;
while (isspace(string[i]) && i >= 0)
{
string[i] = '\0';
i--;
}
}
* @param word_list - The list of words where the words taken from the given
* file will be placed.
* @param file_name - The name of the file to read from.
* @return - The number of words read from the file.
*/
int read_words(char *word_list[MAX_WORDS], char *file_name)
{
int number_of_words_read = 0;
char line[MAX_WORD_LENGTH];
char *pointer;
FILE *file = fopen(file_name, "r");
while (!feof(file))
{
pointer = fgets(line, MAX_WORD_LENGTH, file);
if (pointer != NULL)
{
trim_whitespace(line);
word_list[number_of_words_read] = (char *) malloc(strlen(line) + 1);
strcpy(word_list[number_of_words_read], line);
number_of_words_read++;
}
}
fclose(file);
return number_of_words_read;
}
我将包含我的cygwin终端的屏幕截图,告诉我mvprintw已隐式声明。不知道如何解决这个问题,但也许是问题的一部分。如果此屏幕截图不好,请告诉我,请不要投票。
我认为您只是忘记了包含所需的库
#include <curses.h>
通常,当您收到“函数的隐式声明”警告时,它意味着您可能忘记了包含某些库。
阅读一些有关mvprintw(),endwin()的文档
如果我错了,请原谅,这是我第一次尝试在这里提供帮助:)