[Solved] Explain function returns in c [closed]

Your message functions lack a return type. C deduces it to be int. However, not returning a value from a non-void function is Undefined Behaviour. In your case, the return value from printf has probably been stored in a register, which was not overwritten by message before it itself returned. Thus, the return value propagated. … Read more

[Solved] C: unable to print from file

In your: if ( buff == ‘\n’ && fe && fn ) //<– I assume you want to check if an empty line was read by checking it against the newline character. However, buff is not the character; it is a pointer to were all the characters read are stored. To check if the first … Read more

[Solved] What does “%.7le ” in printf means?

.7 is the precision and le means normal form. double x = 0.012345678910; printf(“%.7lf\n”, x); // 0.0123457 printf(“%.7le\n”, x); // 1.2345679e-02 printf(“%.9le\n”, x); // 1.234567891e-02 Edit See Eric Postpischil’s unswer below, it’s way more comprehensive than this one. 2 solved What does “%.7le ” in printf means?

[Solved] C printf cross-platform format without warnings [duplicate]

For size_t, assuming you have a sufficiently modern C library, use %zu. If you can’t use the z modifier (some older libraries unfortunately don’t support it), cast to a wide-enough known type when printing, and then use a width specifier appropriate to that type: size_t sz = sizeof(whatever); … printf(“%lu”, (unsigned long)sz); This works as … Read more

[Solved] printing * in respective number using printf in C

#include <stdio.h> #include <stdlib.h> int parabola1(int); int *calc(int low, int high, int (*f)(int), int *size, int *min, int *max){ /* #input low, high : range {x| low <= x <= high} f : function #output *size : Size of array *min : Minimum value of f(x) *max : Maximum value return : pointer to first … Read more

[Solved] why printf is not printing here?

Why here the output is only “hie” and “hola”? Order of precedence of Logical AND (&&) is greater than Logical OR (||). Agreed. But, it doesn’t mean that a program has to evaluate in that order. It just says to group together the expressions. Hence, if(printf(“hie”)|| printf(“hello”)&& printf(“nice to see you”)) is equivalent to, if(printf(“hie”) … Read more

[Solved] String manipulation in C (replace & insert characters)

example by use strtok, strchr, sprintf #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ const char *data = “date=2013-12-09 time=07:31:10 d_id=device1 logid=01 user=user1 lip=1.1.1.1 mac=00:11:22:33:44:55 cip=2.2.2.2 dip=3.3.3.3 proto=AA sport=22 dport=11 in_1=eth1 out_1=”; char *work = strdup(data);//make copy for work char *output = strdup(data);//allocate for output char *assignment; //tokenize to aaa=vvv size_t o_count = 0;//output number … Read more

[Solved] Output of Nested printf and scanf in C [closed]

I think what you are missing is, your one line with nested function calls is basically same as this code: int scanf_result = scanf(“%d%d,”,&i,&a); int printf_result = printf(“PRINT %d\t”, scanf_result)); printf(“%d”, printf_result); scanf call should return 2 if you entered valid input, but can also return -1 for actual error, or 0 or 1 if … Read more

[Solved] While true not working [duplicate]

The program most likely gets stuck on the system call. You are printing out text without the trailing newline, so it will be kept in the buffer, until a newline is printed, which you do after the system call. 5 solved While true not working [duplicate]

[Solved] Can’t find issue with “Too many arguments for format” [closed]

all you have to do is correct the %l(there is not such a specifier), you probably should have used %ld. char *buildStatus() { struct rusage *usage = malloc(sizeof(struct rusage)); int usageRet = getrusage(RUSAGE_SELF, usage); if (usageRet == -1) { perror(“RUSAGE fail”); exit(EXIT_FAILURE); } long unsigned cpuTime = (usage->ru_utime).tv_sec + (usage->ru_stime).tv_sec; long memUsed = get_memory_usage_linux(); unsigned … Read more