Output from printf does not show in cygwin terminal? [closed] - c

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I wrote a very small program called cow.c. When I try to run it from the cygwin terminal after compiling, I get no output. There are no errors on compile.
#include <stdio.h>
int main() {
printf("%s\n", "COW?");
return(0);
}
EDIT: I have a feeling that the problem is with cygwin...are there any steps I need to take to ensure that output is printed to the cygwin terminal instead of lost in the void?

Run:
gcc cow.c -o app
Then type:
./app
This should work.

Related

Is there a benefit in doing pthread_exit after pthread_join in main()? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
https://computing.llnl.gov/tutorials/pthreads/samples/join.c
Please see the code in the link above.
Is there any benefit in doing pthread_exit after pthread_join in main()?
Judging from the POSIX specification of pthread_exit(), there isn't much benefit to using pthread_exit() instead of either exit() or _exit() or return. Nominally, it means that atexit() handlers are not executed, and it might mean that file streams are not flushed — more like _exit(). In the context of the sample code, it seems unnecessary.

After I use malloc, program suddenly asks for input [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'm a newbie programmer
//allocating space for final output
//text_count is given by another function, let's just say i have a value for it
//out is my typedef struct
out *fin[text_count];
for(i=0; i<text_count; i++){
fin[i] = malloc(sizeof(out));
}
//this is a test
fin[1]->appearances = 1;
printf("%d",fin[1]->appearances);
// ..other code
I noticed that after this allocation, program suddenly outputs this:
1_
The underscore is blinking, indicating it needs an input.
What can be my problem here? Is it the allocation? Or the codes down below?
okay sorry, let me clarify this, im using codeblocks . so when i get a blinking cursor it means it needs an input. and after i got this output, an infinite loop of inputs seems to be happening.
You're simply seeing the text terminal's cursor. It may be blinking or it may not, that doesn't mean anything in itself.
You might want to add a linefeed:
printf("%d\n", fi[1]->appearances);
to get the output on a line of its own.
A cursor after your printf does not mean, that it is waiting for input.
You can confirm this, by using strace, if it is waiting at read syscall.
Usage:
strace ./myApplication arg1 arg2...

Bit wise or of two Unsigned Integer (Program Crashes) [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Sorry if my problem is not very clear.
I've a structure like this:
typedef struct
{
uint32_t typeSet;
}DataTypeTagInfo;
The following function is for unifying two typeSet:
DataTypeTagInfo* unifyTagInfo(DataTypeTagInfo* tag1, DataTypeTagInfo* tag2){
if(tag1 == NULL) return tag2;
else if(tag2 == NULL) return tag1;
tag1->typeSet |= tag2->typeSet;
return tag1;
}
The program exits while executing the following line:
tag1->typeSet |= tag2->typeSet;
On a sample run I've following value:
tag1->typeSet = 3917954189
tag2->typeSet = 2536589
There is no error message. Just quits. Please help.
The code you show is perfectly sound. Consequently, it's very likely that either tag1 or tag2 is an invalid pointer at the time of the abort. This will have nothing to do with the code you've posted. The pointers could be set invalid in many, many ways.
To figure out what's happening, I'd start with a careful review of the code setting tag1 and tag2 at the call site and then - if the answer does not appear - move on to using valgrind to check for memory overwrite errors.
NB this what makes C(++) so challenging.

UAL Assembly from C to UAL assembly [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
Rewrite the following program in UAL assembly, given its C code. Assume that gcd()
and print() are ABI compliant functions that calculate the greatest common divider
and print the variable respectively. Make sure to annotate your assembly code
int main() {
uint32_t a=0x5, b, i;
b = 4*a;
while(i<10) {
b = gcd(a, b);
i++;
}
print(b);
}
this is for a pre-lab that i am trying to do ... thank you
This does not look like a prelab. It does however look like problem 1 (worth 20 points) that was just assigned in Embedded Systems. You should take the time to learn assembly and the equivalent in C. You will struggle in the class otherwise, since Stack Overflow wont help you on your upcoming exam.... Join a study group if you are having problems with assembly, there are other student in the class dealing with the same issues as you. There is almost always students in the lab as well.
Also, UAL is a ARM Assembly syntax see link:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0473c/BABJIHGJ.html

sizeof operator in c [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
please can anybody help me to implement sizeof() operator in c..
i know the usage .. but i was not able to implement it.
You cannot implement sizeof() as a library function, it is a compiler intrinsic. Are you writing a compiler?
You can't implement sizeof in C; it's a basic operator (you can't implement + either).
You could write a macro that has a limited subset of sizeof's behavior, by doing something along the lines of:
#define thisIsAHorribleHackDontDoThis(a) \
((size_t)((intptr_t)(&a + 1) - (intptr_t)&a))
but that only works if a is an lvalue (and it's horrible to behold). sizeof is not so limited, and that's why you should use it instead of reinventing a wheel that isn't actually round.
Below is the implementation of sizeof operator
#define SZOF(x) (size_t)(((x*)(0))+1)

Resources