我的理解是fgets()返回输入的字符串参数,但是,
我收到"错误:从类型'char*'"分配类型'char [101]'时出现不兼容的类型,
那么,为什么变量'line'被认为是'char [101]'而不是'char*'?
char line[101] = "";
while (feof(filePtr) == 0){
line = fgets(line, 101, filePtr);
strcpy(strPtr, line);
}
Run Code Online (Sandbox Code Playgroud) 我有一个头文件,声明这些数组:
int stVal_On[] = {2};
int stVal_Off[] ={1};
int subVal_On[]={1};
int subMss[]={1};
int subVal_Off[]={0};
Run Code Online (Sandbox Code Playgroud)
然后在声明的结构中使用解除引用的数组:
WriteData结构的定义:
/* Write structure used in loop for Read- and Write Tests */
typedef struct WriteData {
char* name; // MMS object name
const VOID* data; // Data to write
const SINT32 localFormat; // SVI type (on server)
const SINT32 dataLength; // length of data to write/read
const SINT32 NbrofElmnts; // Number of elements to write/read
char* description; // SVI type as String (on server) …Run Code Online (Sandbox Code Playgroud) 在计算圆[3] [6]时,程序似乎在第54行崩溃.可能是什么导致了这个?我输入了一堆打印语句来查找一些信息,所有内容似乎都很好,直到完全[3] [6],这似乎没什么特别的,它崩溃.
int main() {
double a, b, circleXMax, circleYMax, circleRMax;
double rand_float(double a, double b);
int i, j;
int circleInfo = 3;
int circleNum = 50;
int PI = 3.14;
double circleArea;
double circleAreaMax = 0;
double circles[circleInfo][circleNum];
printf("Opened \n");
for(i = 1; i <= circleNum; i++) {
printf("Start of i = %d \n", i);
for(j = 1; j <= circleInfo; j++) {
printf("Start of j = %d \n", j);
if(j == 1 || j == 2) { …Run Code Online (Sandbox Code Playgroud) 如何在不使用C中的头文件的情况下编写hello world?
#include<conio.h>
#include<stdio.h>
void main(){
printf("Hello World");
getch();
}
Run Code Online (Sandbox Code Playgroud)
这是带头文件的简单C程序......
conio.h - 用于控制台stdio.h- 用于printf和scanf所以从我的理解指针变量指向一个地址.那么,以下代码如何在C++中有效?
char* b= "abcd"; //valid
int *c= 1; //invalid
Run Code Online (Sandbox Code Playgroud) 我不明白为什么if以下声明的结果总是不正确的:
unsigned long is_linux;
printf("plz. enter a digit : ");
gets(str);
sscanf(str,"%d",&is_linux);
printf("the value of is_linux = %d \n",is_linux);
if(is_linux==1)
printf("Here is 1 ! \n");
else
printf("There is 0 ! \n");
Run Code Online (Sandbox Code Playgroud)
我只能得到"有0!" 声明,即使我输入"1".此外,printf()语句is_linux正确显示(1)的值:
Run Code Online (Sandbox Code Playgroud)plz. enter a digit : 1 the value of is_linux = 1 There is 0 !
例如,如果我将变量更改为其他名称,则效果很好test.有没有理由不使用is_linux变量?我用gccat 编译了上面的源代码x86_64-redhat-linux.
在Linux gcc 4.4.7中,我需要您的帮助以获得以下警告
for (int iLoop1= 0; iLoop1< iLoopN; ++iLoop1, ++iLoop2, !iIsOk)
Run Code Online (Sandbox Code Playgroud)
我在最后一个逗号之后的最后一个参数中发出以下警告
error: right-hand operand of comma has no effect
Run Code Online (Sandbox Code Playgroud)
我已经阅读了逗号运算符的wiki页面,但我不明白这个问题 https://en.wikipedia.org/wiki/Comma_operator
编辑:有效!iIsOk没有做任何我测试以下代码
// Example program
#include <iostream>
#include <string>
#include <iostream>
int main()
{
int iIsOk = 0;
for (int iLoop1 = 0; iLoop1 < 2; iLoop1++, !iIsOk)
{
std::cout << "IsOk=" << iIsOk << std::endl;
}
for (int iLoop1 = 0; iLoop1 < 2; iLoop1++, iIsOk = !iIsOk)
{
std::cout << "IsOk2=" << iIsOk << std::endl;
} …Run Code Online (Sandbox Code Playgroud) 问题是当我尝试输入一个带空格编译器的字符串渲染时,将其作为单独的2个字符串.但要求是每当字符串中有空格时不要将其视为2个字符串,而是将其视为单个字符串.只有当我的四个输入是MAHIRL,CHITRA,DEVI和C时,程序才会打印出来.我的代码是:
#include<stdio.h>
#include<string.h>
int main()
{
char str1[10],str2[10],str3[10],str4[10];
scanf("%s",str1);
scanf("%s",str2);
scanf("%s",str3);
scanf("%s",str4);
if(strcmp(str1,"MAHIRL")==0 && strcmp(str2,"CHITRA")==0 && strcmp(str3,"DEVI")==0 && strcmp(str4,"C")==0 ){
printf("yes");
}
else{
printf("no");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用strtok()和strpbrk(),但我不太确定如何在我的代码中实现它们.任何帮助或建议表示赞赏.谢谢.
我有以下功能的问题.
当我尝试realloc()记忆时,我得到的比实际要求的要多!
在这种情况下我会再做连接两个字符串,一个谁是14个字符长,一个谁是长11个字符,但最终的结果是,memTemp长38个字符,即使memNewSize表明,它实际上是在25,没有人知道该怎么办?
int dstring_concatenate(DString* destination, DString source)
{
assert(destination != NULL); // Precondition: destination ar ej NULL
assert(*destination != NULL); // Precondition: *destination ar ej NULL
assert(source != NULL); // Precondition: source ar ej NULL
//Dstring looks like this = "typedef char* Dstring;"
int memNewSize = strlen(*destination) + strlen(source);
char *memTemp;
memTemp = (char*)realloc(memTemp, sizeof(char) * memNewSize);
printf("%d\n", memNewSize);
printf("%d\n", strlen(memTemp));
if(memTemp == NULL)
{
printf("Could not allocate new memory.\n");
return 0;
} …Run Code Online (Sandbox Code Playgroud) 我看到指向单个变量或C中的数组的指针是使用相同的语法声明和打印的.所以我想在正则表达符号*中*调用many,这意味着许多如x*= xxx ....
int a[3] = { 4, 5, 6 };
int b = 3;
int *p, *q; // same syntax for either single variable or array
p = a; // pointer to many int
q = &b; // pointer to an int
printf("%d %d", *p, *q); // same syntax again
Run Code Online (Sandbox Code Playgroud)
因此,pointer to many int为了便于理解,我可以同时调用p和q 吗?