could somebody give out some basic examples of this code? [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I really don't understands this code:
#include <stdio.h>
int main (int argument c, char *argument v[])
{
return 0;
}
What does this code mean? How does it converts to other formation of coding?

This is (almost) the simplest C/C++ program. (It works for both languages.) It does nothing other than return 0, which signifies successful execution.
It should read
int main(int argc, char **argv)

Related

Alternatives for str.substr using <cstring> library? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
Hi I was wondering if there is an alternative of str.substring() in string.h. If not, what is an efficient alternative?
Assuming that we all agree that using c++ it is safer and more professional to use the standard library tools.
That said, if we're talking about C and not C++, this should be one of the ways to extract a substring with the "string.h" library:
#include <stdio.h>
#include <string.h>
int main() {
char test[] = "abcdef";
char subtext[3];
memcpy(subtext, &test[1], 2); //Result: "bc"
subtext[2] = '\0';
printf("%s", subtext);
return 0;
}

Can I make a float number in a C program always round up [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Can I make a float number in a C program always round up
You can use the ceil() function. For example:
#include <stdio.h>
#include <math.h>
int main () {
float val1 = 1.6;
printf ("Round up to %.1lf\n", ceil(val1));
return(0);
}

C programming read a integer from command line input string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I just started programming and have a question. I have a example input from command line: "number:10" which is "number:" followed by a number. I want to check if the character after "number:" is a number:
int main(int argc, char **argv)
{
if(isdigit(*argv[2]+7)){
printf("correct");
}
return 0;
}
It doesn't work. How can I read only the number in the input string?
*argv[2] is 'n'. *(argv[2]+7) is correct

Differences between scanf and getchar in C [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I was trying to explain to my friend something about C coding and he asked me why his code (with "scanf") didn't work.
#include
int main() {
char x=scanf("%c",&x);
printf("%c\n",x);
return 0;
}
and this one yes
#include <stdio.h>
int main()
{
int k;
char x=getchar
printf("%c\n",x);
return 0;
}
When scanf completes, x contains the character that was read. However, that value is immediately overwritten when x is assigned the return value of scanf, which is the number of items successfully matched or EOF in the event of an error.
If you call scanf without assigning the return value to x you should get the expected result.
For example, this should work.
char x;
scanf("%c",&x);

Why does this print 1? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
#include <stdio.h>
int main()
{
int var=0;
for(; var++; printf("%d",var));
printf("%d", var);
}
Please explain to me this C code. How is the output 1?
You might be confused because of the wrong code indentation. Your code is:
for(; var++; printf("%d",var))
;
printf("%d", var);
So you always get the output of the second printf. As var is initialized to 0 and var++ (the for-condition) is always executed, you end up with var==1.

Resources