简体   繁体   English

是否可以输入某种变量并在C中同时将其与另一个变量进行比较?

[英]Is it possible to input a variable of some sort and compare it with another variable at the same time in C?

I was wondering if there was possibly a way where one could scan a variable and then compare it all in the same line (same time). 我想知道是否可能有一种方法可以扫描一个变量,然后将它们全部在同一行(同一时间)进行比较。

So far I tried this: 到目前为止我试过这个:

if(strcmp((scanf("create.%s",comp)),comp)==0)          //Please do not mind any missed parentheses or something like that...

I know ^that doesn't work because I've tried it and it ended up with an error... 我知道^那不起作用,因为我已经尝试过了,结果却出现了错误......

So how would one achieve such a task? 那么如何实现这样的任务呢? Or is it impossible? 还是不可能?

  1. It didn't work since scanf returns length, not char pointer 它没有工作,因为scanf返回长度,而不是char指针
  2. The fact that you write it in the same line have nothing to do with the execution time, you might as well separate it into two parts. 你在同一行写它的事实与执行时间无关,你可以将它分成两部分。
  3. If you really really want to do that (and I see no reason to), you may do the following: 如果你真的想这样做(我没有理由),你可以做以下事情:

     char *superScanfWithString(const char *format, char * str) { scanf(format,str); return str; } ... if(strcmp((superScanfWithString("create.%s",comp)),comp)==0) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以比较C中相同变量的字符串? - Is it possible to compare strings from the same variable in C? 如何提取一部分 char 然后将其与 C 中的另一个变量进行比较 - how to extract a part of char then compare it with another variable in C 初始化变量并同时指定存储地址:是否可能? - Initializing a variable and specifying the storage address the same time: is it possible? 在C中用另一个变量命名变量 - Naming a variable with another variable in C 如果同时执行又如何从另一个可执行文件访问变量? - how to access a variable from another executable if they are executed at the same time? 比较“ argv”和“ int”变量(C) - Compare “argv” and a “int” variable (C) 在C语言中,是否可以在运行时通过指针访问变量名 - In C, is it possible access a variable name at run time via pointer 在 c 中怎么可能有同名但不同类型的变量? - How is possible to have variable with the same name but different type in c? 如何读取 C 中的文件并同时创建具有行数的变量? - How to read a file in C and at the same time create a variable with the number of lines? 可以在c中的变量上同时使用前缀和后缀 - can prefix and post be used at the same time on a variable in c
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM