in a struct, scanf returns var address not value

I tried to print the value of an int variable of a struct but it prints out the address instead.. don't know why, here is the code: struct data{ char name[20]; int age[100]; }; typedef struct data dataobj; int main() { dataobj element; printf("enter a name:n"); gets(element.name); printf("name is: %sn",element.name);

在一个结构中,scanf返回的是无效地址

我试图打印一个结构的int变量的值,但它打印出的地址,而不是..不知道为什么,这里是代码: struct data{ char name[20]; int age[100]; }; typedef struct data dataobj; int main() { dataobj element; printf("enter a name:n"); gets(element.name); printf("name is: %sn",element.name); printf("enter a number:n"); scanf("%d",&e

How do I re enter an integer value in a 'while' loop?

printf("please enter a value for side a: "); check1 = scanf(" %d*%c", &a); while(check1 != 1) { printf("You have entered an invalid value"); scanf(" %d*%c", &a); } printf("The value for A is: %dn", a); I am trying to make sure that the entered value is an integer only with (check1 != 1). if I enter anything other than an integer and the while loop engages, it infinitely p

我如何在'while'循环中输入整数值?

printf("please enter a value for side a: "); check1 = scanf(" %d*%c", &a); while(check1 != 1) { printf("You have entered an invalid value"); scanf(" %d*%c", &a); } printf("The value for A is: %dn", a); 我试图确保输入的值是一个只有(check1!= 1)的整数。 如果我输入除整数以外的任何值并且while循环占用,它将无限打印“您输入的值无效”,但忽略scanf以重新输入A的值。 我在这之前

c program ignores all scanfs after wrong variable type input

#include <stdio.h> #include <stdlib.h> int main(void) { int a, b, checka, checkb; printf ("enter a: "); checka = scanf ("%d", &a); printf ("enter b: "); checkb = scanf ("%d", &b); printf ("checka = %dn", checka); printf ("checkb = %d", checkb); return EXIT_SUCCESS; } I was having this problem in a larger program but I wrote a quick test to see i

c程序忽略错误的变量类型输入后的所有scanfs

#include <stdio.h> #include <stdlib.h> int main(void) { int a, b, checka, checkb; printf ("enter a: "); checka = scanf ("%d", &a); printf ("enter b: "); checkb = scanf ("%d", &b); printf ("checka = %dn", checka); printf ("checkb = %d", checkb); return EXIT_SUCCESS; } 我在一个更大的程序中遇到了这个问题,但我写了一个快速测试,看看我能不能修复它,

scanf and wrong input makes output wierd

I have the following code in C: #include <stdio.h> #include <stdlib.h> int var(); int var() { return 10; } void main() { int a; double x; a=0; a=var(); printf("hello world, i am a function which returned the value %d",a); printf("nnow you enter a value:"); scanf("%d",&a); printf("so you entered the value: %d",a); printf("nnow enter a dou

scanf和错误的输入会使输出变得更加奇怪

我在C中有以下代码: #include <stdio.h> #include <stdlib.h> int var(); int var() { return 10; } void main() { int a; double x; a=0; a=var(); printf("hello world, i am a function which returned the value %d",a); printf("nnow you enter a value:"); scanf("%d",&a); printf("so you entered the value: %d",a); printf("nnow enter a double value:")

While loop hangs program after valid input is entered?

I have been stuck with this problem on and off since last night and I'm hoping a second fresh pair of eyes will help. The problem, if an invalid input is entered in the userIn function (anything that isn't a number between 1-99) the test printf at the end of the while loop in main prints "ERR = 1", the while loops and userIn is called again. So far so good, but when a valid i

while循环在输入有效输入后挂起程序?

自从昨晚开始,我一直在关闭这个问题,我希望第二个新的眼睛会有所帮助。 问题,如果一个无效的输入在输入userIn函数(任何不1-99之间的数字)在while循环的端部的测试的printf main打印“ERR = 1”时,while循环和userIn再次被调用。 到目前为止这样好,但是当输入一个有效的输入时,while循环结束时的测试printf打印“ERR = 0”,然后程序挂起。 说“HELLO”的测试printf永远不会被打印。 任何建议,为什么是最受欢迎的。 代

c Infinite loop error

The program builds properly, but I'm getting an infinite loop of random numbers and I'm not sure why. I int getInt(void); double getDbl(void); void prnTitle(void); void prnFooter(double gTotal); void pause(void); double getDblLimited(double lowerLimit, double upperLimit); comment out the main when submitting milestone one Your final milestone one should run perfectly with the followi

c无限循环错误

该程序正确构建,但我得到一个无限循环的随机数,我不知道为什么。 一世 int getInt(void); double getDbl(void); void prnTitle(void); void prnFooter(double gTotal); void pause(void); double getDblLimited(double lowerLimit, double upperLimit); 在提交里程碑之一时注释掉主要内容 您的最后一个里程碑应该通过以下测试程序完美运行。 注释掉main()删除箭头后面的下两个字符 int main (void) { int iVal;

point of arguments in main function

This question already has an answer here: What does int argc, char *argv[] mean? 8 answers Depending on what type of application you are developing this may or may not be relevant to you. But arguments are intended for your command line arguments that are passed to the application at run time. The prototype is int main (int argc, char ** argv); If you invoke your application from the co

主要功能中的论点点

这个问题在这里已经有了答案: int argc,char * argv []是什么意思? 8个答案 取决于您正在开发的应用程序类型,这可能与您相关,也可能不相关。 但是参数用于在运行时传递给应用程序的命令行参数 。 原型是 int main (int argc, char ** argv); 如果你从命令行调用你的应用程序 ./a.out foo bar 然后main会通过 argc = 2 argv = {"foo", "bar", NULL} 对于其他有效的原型main是 int main(void); 如果你不需要

declare a function in main?

Some example i run into for a program that deals with menu.. He declared all the function before the main function as i understand should be, and then one of the function that is a void function was also mentioned inside the main: char get_choice(void); char get_first(void); int get_int(void); void count(void); int main(void) { int choice; void count(void); while ( (choice = get_ch

在main中声明一个函数?

我遇到一个处理菜单的程序的例子。 他在main函数之前声明了所有的函数,据我所知应该是这样,然后在主函数中也提到了一个void函数的函数: char get_choice(void); char get_first(void); int get_int(void); void count(void); int main(void) { int choice; void count(void); while ( (choice = get_choice()) != 'q') { switch (choice) { case 'a' : printf("Buy low, sell

What these C's main function indicates?

Possible Duplicate: Why is the type of the main function in C and c++ left to the user to define? I've come across many C's main function style and syntax of writing but I'm not actually getting what this syntax mean can anybody give brief on each syntax? why void? why int? why void,int as parameter? void main() { } int main() { } int main(void) { } void main(void) { }

这些C的​​主要功能是什么?

可能重复: 为什么C和c ++中的主要函数的类型留给用户去定义? 我遇到过很多C的主要函数风格和编写的语法,但实际上我没有得到这个语法的意思,任何人都可以给出每种语法的简要说明吗? 为什么无效? 为什么是int? 为什么void,int作为参数? void main() { } int main() { } int main(void) { } void main(void) { } int main(int) { } int main(int argc, char* argv[]) { } c标准指定了两种形式的一致性

Regarding 'main(int argc, char *argv[])'

Possible Duplicates: What are the arguments to main() for? What does int argc, char *argv[] mean? Every program is starting with the main(int argc, char *argv[]) definition. I don't understand what it means. I would be very glad if somebody could explain why we use these arguments if we don't use them in the program? Why not just: int main() ? Is the name of the program one of

关于'main(int argc,char * argv [])'

可能重复: main()对于什么参数? int argc,char * argv []是什么意思? 每个程序都以main(int argc, char *argv[])定义开始。 我不明白这意味着什么。 如果有人能够解释为什么我们在程序中不使用这些参数,我会很高兴。 为什么不只是: int main() ? 是程序的名称的要素之一*argv[]和argc是参数的数量的计数*argv[] 发送给*argv[]的其他参数是什么? 我们如何发送它们? 这些参数argc和argv的main被用作一