标签: scanf

scanf() is not waiting for user input

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)

c scanf

-1
推荐指数
1
解决办法
2万
查看次数

scanf读取每一个双错

我有以下代码:

    int main(void)
{
    double r;
    scanf("lf",&r);
    printf("%lf\n",r);
}
Run Code Online (Sandbox Code Playgroud)

我输入的任何值都会返回一个大约 40-50 位数字的无意义数字。scanf 可以很好地处理字符、整数、字符串等,但对于双精度数我会遇到这个问题。有谁能够帮助我?

c double scanf lf

-1
推荐指数
1
解决办法
440
查看次数

忽略 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 scanf

-1
推荐指数
1
解决办法
818
查看次数

使用scanf()函数的C编程中的意外输出

我在这样的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个输入,仅显示前两个,我也不知道为什么。有任何想法吗 ?

c scanf

-1
推荐指数
1
解决办法
50
查看次数

如何使用scanf函数获取字符串长度

如何在不使用strlen函数或计数器的情况下获取字符串长度,例如:

scanf("???",&len);
printf("%d",len);
Run Code Online (Sandbox Code Playgroud)

输入: abcde

预期输出: 5

c string scanf

-1
推荐指数
1
解决办法
1018
查看次数

如何用c语言的fscanf从文件中读取数据

我想用“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)

我希望有人可以帮助我,我是初学者;-) 非常感谢!

c arrays scanf

-1
推荐指数
1
解决办法
577
查看次数

C - fscanf() - 将数据读入数组

将数据读入数组时遇到奇怪的错误.我的目标是逐行读取具有单列数字的文件到一个数组中.

#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之前的预期表达式:错误:下标值既不是数组也不是指针

c arrays scanf

-2
推荐指数
1
解决办法
2万
查看次数

scanf("%d",i)如何工作?

考虑这段代码(而不是使用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()的确如何运作?

c scanf

-2
推荐指数
1
解决办法
177
查看次数

sscanf_s,双倍%c

当我想提取两个字符时,我遇到了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,一切都正常.

c++ scanf

-2
推荐指数
1
解决办法
230
查看次数

sscanf的行为是不同的

#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失败以及为什么它无法检索最后一个变量?

c scanf

-2
推荐指数
1
解决办法
96
查看次数

标签 统计

scanf ×10

c ×9

arrays ×2

c++ ×1

double ×1

lf ×1

string ×1