I am working on making tree using doubly linked list in c. I use recursive call in that function , but somehow it do not works. my code is :
struct node
{
int data;
struct node *right;
struct node *left;
};
struct node* getNode()
{
struct node *temp;
temp= (struct node *)malloc(sizeof(struct node));
temp->right=NULL;
temp->left=NULL;
return temp;
}
Run Code Online (Sandbox Code Playgroud)
here in the below function I am getting the problem.
struct node* maketree()
{
struct node *t;
t=getNode();
int value;
char …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
int main(void)
{
double r;
scanf("lf",&r);
printf("%lf\n",r);
}
Run Code Online (Sandbox Code Playgroud)
我输入的任何值都会返回一个大约 40-50 位数字的无意义数字。scanf 可以很好地处理字符、整数、字符串等,但对于双精度数我会遇到这个问题。有谁能够帮助我?
我使用scanf给定格式读取输入:
scanf("<%d;%d>%c", &lo, &hi, &op);
Run Code Online (Sandbox Code Playgroud)
这接受一些像<1;10>k. 当我完全按照该语法输入时,这有效,但它不适用于空格,因此例如这将不起作用:
< 1 ;
3 >
k
Run Code Online (Sandbox Code Playgroud)
那么如何scanf忽略这些空格呢?
我在这样的C编程中获得了意外的输出(https://imgur.com/a/4aopLjI)。
#include<stdio.h>
int main(void) {
int i,j;
scanf("%d ",&i);
scanf("%d ",&j);
printf("\n%d \n",i);
printf("%d",j);
}
Run Code Online (Sandbox Code Playgroud)
该程序似乎接受3个输入,仅显示前两个,我也不知道为什么。有任何想法吗 ?
如何在不使用strlen函数或计数器的情况下获取字符串长度,例如:
scanf("???",&len);
printf("%d",len);
Run Code Online (Sandbox Code Playgroud)
输入: abcde
预期输出: 5
我想用“fscanf”导入数字(总共 40000 个,以空格分隔)(格式:2.000000000000000000e+02)并将其放入一维数组中。我尝试了很多事情,但得到的数字很奇怪。
到目前为止我所拥有的:
int main() {
FILE* pixel = fopen("/Users/xy/sample.txt", "r");
float arr[40000];
fscanf(pixel,"%f", arr);
for(int i = 0; i<40000; i++)
printf("%f", arr[i]);
}
Run Code Online (Sandbox Code Playgroud)
我希望有人可以帮助我,我是初学者;-) 非常感谢!
将数据读入数组时遇到奇怪的错误.我的目标是逐行读取具有单列数字的文件到一个数组中.
#include <stdio.h>
int main() {
int numArray = [20];
int i = 0;
FILE *infile;
infile = fopen("numbers", "r");
while(!feof(infile))
{
fscanf(infile,"%d",&numArray[i]);
i++;
}
fclose(infile);
return 0; }
Run Code Online (Sandbox Code Playgroud)
这是我的编译错误:
sort_algorithms.c:在函数'main'中:sort_algorithms.c:6:错误:在'['标记sort_algorithms.c:16之前的预期表达式:错误:下标值既不是数组也不是指针
考虑这段代码(而不是使用scanf(%d,&i)我故意使用scanf("%d",i))
int main()
{
int i;
scanf("%d", i);
printf("%d", i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里我没有初始化,代码正在运行时发出警告,扫描输入并将垃圾值作为输出.
但如果我初始化了一些值,那么它会扫描输入和程序崩溃.
两种情况下scanf()的确如何运作?
当我想提取两个字符时,我遇到了sscanf_s的一些问题.
示例代码:
#include "stdafx.h"
#include <iostream>
#include <string.h>
int _tmain(int argc, _TCHAR* argv[])
{
char* text = "ab";
char a = ' ';
char b = ' ';
sscanf_s(text, "%c%c", &a, &b); //the same problem when I use %1c%1c
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,这不起作用:
ConsoleApplication2.exe中0x0F76D6AC(msvcr120d.dll)的未处理异常:0xC0000005:访问冲突写入位置0x00000000.
当我尝试使用两个整数时%i%i,一切都正常.
#include <stdio.h>
int main()
{
char * msg = "Internal power 10. power sufficient. total count 10";
char * temp = "Internal power %d. power %s. total count %d";
int v1, v2, ret;
char str1[64];
ret = sscanf(msg, temp, &v1, str1, &v2);
printf("%d\n", ret);
printf("%d %s %d ", v1, str1 , v2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我想了解为什么sscanf失败以及为什么它无法检索最后一个变量?