Tag: 声明

用动态内容声明arraz

你好我想制作程序,它会说明这个词中有多少大字母和短字母但是这个问题我不能动态地声明数组的内容。 这是所有C代码。 我试过这个 char something; scanf(“%c”,somethnig); char somethingmore[]=something; printf(“%c”,something[0]) 但是编译不可能我也试过这样的东西 char *something; scanf(“%c”,something); printf(“%c”,something[0]); 有可能编译但被称为数组指针时压缩(如果命名是错误的我就是apoligize)我编程初学者所以这可能是愚蠢的问题。 这只是我运行的问题的一个例子,而不是我的程序的代码。

创建数组的动态声明

我想要动态声明的make数组我想象像这样的somethnig。我想要make程序识别单词中的字符。 char i; scanf(“%c”,&i); char word[]=i; printf(“%c”,word[0]); 我也试过这样的事情 char i; scanf(%c,&i); char *word=i; printf(“%c”,word[0]); 我不知道如何使它工作

C一个函数的明确声明

我在Linux和gcc 4.2.3上。 对于下面的代码部分,隐式调用lp_parm_talloc_string函数,然后定义它: char *lp_parm_string(const char *servicename, const char *type, const char *option) { return lp_parm_talloc_string(lp_servicenumber(servicename), type, option, NULL); } /* Return parametric option from a given service. Type is a part of option before ‘:’ */ /* Parametric option has following syntax: ‘Type: option = value’ */ /* the returned value is talloced in […]

是否需要在头文件中声明所有C函数

我是否需要在头文件中声明我在.c文件中使用的所有函数,或者我可以直接在.c文件中声明和定义? 如果是这样,在这种情况下.c文件中的定义是否也算作声明?

数组成员的值变化不合逻辑

当我声明一个数组时,我注意到了 int arr[10]; 过了一会儿,虽然在一段时间内没有任何影响,但数组成员的值会发生变化。 然后我用“新”动态分配,问题解决了。 我认为一切都应该动态声明。 但这不应该是真的。 什么是合乎逻辑的原因?

声明一个结构数组

我正在尝试创建一个结构数组,但它出现了这个错误: “错误,数组类型为不完整的元素类型” typedef struct { char data[MAX_WORD_SIZE]; int total_count; Occurrence_t reference[MAX_FILES]; int nfiles; } Word_t; struct Word_t array[a];

使用cpp / c ++中的字符串值数据声明变量名称

例如,假设您从某处提取数据并将其放入字符串变量中,然后您希望将其中的数据用作另一个字符串名称: int main(void){ string strVar =”StringData”; //this is a string variable with text inside cout<<strVar<<endl; //displaying the variables contents string strVar.c_str() = "stuff in string variable 'StringData'"; //this uses what was inside of strVar to be the name of the new string variable cout<<StringData<<endl; //prints the contents of the variable StringData (who got its name […]

这是正确的C声明吗? 如果是这样,为什么它不起作用?

我正在编写一本教程书中的演示程序,用于教授Unix和Windows的“C”。 但是,有时我会遇到一些代码,当完全输入时,它不想工作。 例如。 #include int main() { /*This next line is the error */ int num = 2, bool = 0; if ( (num==2) && (!bool) ) { printf(“The first test is untrue\n”); } else if( (num==2) && (!bool) ) { printf(“The second test is true\n”); } else if( (num==2) && (bool==0) ) { printf(“The […]

在C中,为什么在单独的语句中定义全局变量会引发警告,但是对于局部变量是否可以?

在下面的代码中,为什么全局变量“x”的定义显示警告“数据定义没有类型或存储类”,但同样的事情适用于局部变量“y”?我正在为每个变量做什么首先在一个语句中声明它们,然后在另一个语句中定义它们。它对一个语句有效但是对另一个语句显示警告的区别是什么? #include int x; x=303; int main(void) { int y; y=776 ; printf(“The value of x is %d,and of y is %d”,x,y); }

函数声明顺序在c语言中是重要的还是我做错了什么?

我收到此错误: arthur@arthur-VirtualBox:~/Desktop$ gcc -o hw -ansi hw1.c hw1.c: In function `main’: hw1.c:27:16: warning: assignment makes pointer from integer without a cast [enabled by default] hw1.c: At top level: hw1.c:69:7: error: conflicting types for `randomStr’ hw1.c:27:18: note: previous implicit declaration of `randomStr’ was here 在编译此代码时: #include #include int main(int argc, char** argv) { char *rndStr; rndStr […]