Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have following C program and I am not understanding some point of this program
#include <stdio.h>
int main()
{
char ara[100];
while(NULL != gets(ara))
{
printf("%s\n", ara);
}
return 0;
}
If I input some string like Hello World, this code return me the output same as input. But, what is NULL and gets?? Are they from C library? Why their colour not changed when I compile them?
Please read description of function gets()!
This function reads string from stdin. It returns NULL if found end of line or end of file before any characters.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
Can anyone please provide me the code in c programming language of problem in which we enter "ABCD" as an input in run time and we get "ZYXW" as output and I tried to solve this using ASCII Code
Hope this will help you . Read about ascii code of character . Also you have to gain knowledge of pointer and string .
#include<stdio.h>
int main(){
char ch[20];
scanf("%s",ch);
for(const char *s = ch; *s; ++s)
putchar('Z'-(*s-'A'));
return 0;
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following code:
int (*predicate)(char) = 0;
Can anyone tell me what this code means? What is the meaning of the word predicate in C?
The sentence is a declaration and definition of a pointer to a function taking one argument (char) and returning int. The pointer is initialized to the null pointer value.
The word "predicate" is the programmer's choice for the variable name.
Reference: cdecl
One might use predicate like this:
/* UNTESTED */
int IsLower(char c) { return c >= 'a' && c <= 'z'; }
int main () {
int (*predicate)(char);
predicate = IsLower;
if ( (*predicate)('f') == 1 ) printf("'f' is lower case!\n");
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
#include <stdio.h>
int hledejznak(x)
{
int c;
int pocitadlo=0;
while((c=getchar())!=EOF)
{
if(x==c){
pocitadlo++;
while((c=getchar())!=32)
{
printf("%d\n",c);
};
};
};
return pocitadlo;
}
int main(int argc,char *argv[])
{
int znak=*argv[1];
printf("answer is %d",hledejznak(znak));
return 0;
}
Hi people, I need to count words containing character specified as argument at terminal
example: echo 'hello babe' | ./main e
Answer is 2
....because there are two words containing letter "e"
My code doesn't work, can you help me?
Thanks
Don't nest your loops; keep the outer one that processes each character read
Have a boolean variable initalized to false & set to true whenever you see the desired character.
Whenever a word ends, increment your counter if the flag is true. Either way, set the flag to false (to get ready for the next word). (Note that the last word may NOT end with a space.)
Only when you're processed all of the input should you print the value of the counter.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I would like to iterate through all the record entries in /etc/passwd using just c api calls.
How can I do this?
Note: I've seen lots of examples of how to do this in other languages, but not found any examples in c.
This small program worked for me:
#include <stdio.h>
#include <pwd.h>
int main(int argc, char **argv) {
struct passwd *pw;
setpwent();
while ( (pw = getpwent()) != NULL )
{
printf("%s\n", pw->pw_name);
}
endpwent();
return 0;
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Its C program which is running x86_64 machine ,Wanted to know how output is coming like this way
main()
{
int *mess;
mess=malloc(1);
mess[0]=1;
//mess[1]=2;
printf("%d",mess);
}
Now output here is 6295568
How is it??
You're printing the address where your int is stored. You need
printf("%d",*mess);
to print its value.
You are also allocating too little space for your int, you should do:
int *mess = malloc(sizeof(int));
instead of
int *mess = malloc(1);