Tag: 数组

检查一个字符串是否只有C中的数字?

我正在尝试编写一个简单的代码来检查字符串中是否只有数字。 到目前为止,它不起作用,任何帮助将不胜感激。 #include #include #include int main() { char numbers[10]; int i, correctNum = 0; scanf(“%s”, numbers); for(i = 0 ; i <= numbers ; ++i) { if(isalpha(numbers[i])) { correctNum = 1; break; } } if(correctNum == 1) { printf("That number has a char in it. FIX IT.\n"); } else { printf("All numbers. Good.\n"); } […]

确保用户的输入与我的程序生成的字符匹配

这是为家庭作业 我正在编写一个简化的拼字游戏,我让我的程序随机生成字符然后用户会尝试从这些生成的字符创建一个单词,然后得到一个分数。 我遇到的问题是确保用户实际使用提供的字符。 我不知道如何处理这个问题。 我不需要任何代码,但提示将被赞赏,甚至链接开始点。 谢谢你的帮助! 编辑 – 大约我的一半程序[创建字母集的部分] void generate_letter_set(int letter_set[] , int size_let , int num_let) { int arr[N]; const char let[] = {‘K’,’J’,’X’,’Q’,’Z’,’B’,’C’,’M’,’P’,’F’,’H’,’V’,’W’,’Y’,’G’,’L’,’S’,’U’,’D’,’N’,’R’,’T’,’O’,’A’,’I’,’E’}; const int freq[] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 6, 6, 6, 8, 9, […]

当数组为空时,ARRAY_SIZE是否返回未定义的行为?

当数组为空时,ARRAY_SIZE是否返回未定义的行为? 因为我们做了一个不存在的sizeof((X)[0]) #include #include #include #ifndef ARRAY_SIZE #define ARRAY_SIZE(X) sizeof((X))/sizeof((X)[0]) #endif struct ka { int a; int b; }; int main(void) { struct ka k[] = {}; printf(“%d\n”, ARRAY_SIZE(k)); }

获取错误Xlib:显示“:24.0”时缺少扩展名“RANDR”。 GTK

我收到这个错误,不知道为什么……请看看我的按钮数组,也许我搞砸了那里,我不确定…我得到的错误是: Xlib: extension “RANDR” missing on display “:24.0”. 之后没有任何事情发生,这意味着我的计划根本没有运行…. #include /* Our new improved callback. The data passed to this function * is printed to stdout. */ static void callback (GtkWidget *widget, gpointer data) { system ((gchar *) data); } /* another callback */ static gboolean delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) { gtk_main_quit […]

char str 和char * str作为函数参数有什么区别?

假设我们有以下函数原型: void function1(char str[]); void function2(char *str); 现在说我们有一个字符串char name[] = “John”; 我们希望通过这些function。 两者有什么区别? 它们的用途和局限是什么? 是否存在一种优先于另一种情况的情况? 如果将字符串初始化为char *name = “John”它会有所作为吗? 我理解在函数中使用char str[]和char *str之间的区别,但我不知道它们作为函数参数或参数的行为。

在malloc.c中断言:2453

我有以下程序试图标记一个字符串(基于空格)并将其写入char **数组。 #include #include #define len 180 void tokenize(char *str, char **tokens) { int l = 0, index = 0; int i = 0; int str_i; int tok_i; while(*str) { if (*str == ‘ ‘) { tokens[i] = malloc(sizeof(char) * l+1); if (tokens[i] == NULL) return; tok_i = 0; for (str_i=index-len ; str_i<index ; str_i++) […]

在一个函数中对5个数组进行排序

如果我有5个数组和一个包含所有5个数组的指针数组,我需要编写一个只使用指针数组对每个数组进行排序的函数,我该怎么做? 该函数需要从索引1(!)开始对数组中的每一个进行排序,而不是0。 int arr1[] = { 3, 9, 6, 7 }; int arr2[] = { 2, 5, 5 }; int arr3[] = { 0 }; int arr4[] = { 1, 6 }; int arr5[] = { 4, 5, 6, 2, 1 }; int * parr[] = { arr1, arr2, arr3, arr4, arr5 }; 我知道如何对一个数组进行排序,但是当我尝试以最有效的方式使用指针数组对每一个数组进行排序时,我有点失落。 也许有一个选项可以在一个循环中对每个数组进行排序? […]

将for循环中的值存储到数组中

我想将从for-loop读取的值存储到数组中 char A[]; int x; int y=5; for( int i=0; int i =1000; i++) { x = x+y; // then store/append x as elements of the char array, A…. what is the syntax? }

在C中的数组中强制执行范围

快速,可能是超级基本问题。 如果我声明一个10个双精度数组并提示用户输入他们想要的索引数量(显然在1到10之间),我将如何强制执行该范围? 我假设使用if / else语句,但是有更强的方法来强制执行该范围吗? 再说一次,可能很简单。 我是新手,所以还不熟悉C ++或JavaScript。

为什么C ++不支持可变长度数组?

可能重复: C ++中的可变长度数组? 我只是好奇,C ++不允许变长数组有什么特别的原因吗?