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?

Answers


  1. It didn't work since scanf returns length, not char pointer
  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) 
    

Need Your Help

Facebook Open Graph PHP SDK event picture

facebook facebook-graph-api facebook-php-sdk

I have a problem with adding picture to the FB event. To create event I use FB PHP SDK.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.