c

How to print a positive number as a negative number via printf

While reading about printf(),I found that it can print numbers as positive or negative as desired by the user by following code(for -).But the code doesnt work and the output is a positive value.Please mention where the error is.Thanks #include<stdio.h> int main() { printf (" %-d\n", 1977); return 0; } ...

C - array of strings scope difference

I practiced an array of strings with no initial values. Attempt 1 #include <stdio.h> char *array[] = {}; int main(int argc, char *argv[]) { array[0]="Hello"; array[1]="World"; char **i = array; while (*i) { printf("%d %s\n", i, *i); i++; } } $ gcc array_of_strings.c && ./a.out 6293704 Hello 6293...

What is more efficient with C code?

What is more efficient with the C code I am working with, moving my code into an existing C program or have an h file #included so it calls the separate .c file? When this is compiled into an .exe how does this work with having it incorporated into the original code vs having an h file and separate .c file? I am not sure how many lines...

What type-conversions are happening?

#include "stdio.h" int main() { int x = -13701; unsigned int y = 3; signed short z = x / y; printf("z = %d\n", z); return 0; } I would expect the answer to be -4567. I am getting "z = 17278". Why does a promotion of these numbers result in 17278? I executed this in Code Pad. ...

Unknown size error

I have to use this code but I get receive the following error: error c2036'Complex_Z 'unknown size typedef struct Complex_Z{ double r, i; } ; void update_projection_zprimme(struct Complex_Z *X, struct Complex_Z *Y, struct Complex_Z *Z, int numCols, int maxCols, int blockSize, struct Complex_Z *rwork, struct primme_param...

C homework, ignore for now (I think I am going repost later with some code)

I am going to be making a program that reads in a line and gets up to 6 numbers. The program will eventually solve a a square matrix between 2x2 and 6x6. My question is what errors do I need to look for on the get_numb() function? I am thinking that the function will have to check character by character to make sure that the individ...

What is the Delphi equivalent of ' unsigned char** ' in C

What is the Delphi equivalent of unsigned char** ' in C i'm not sure if its a pointer to an array or a pointer to a pointer or if the two things are the same in C. ...

c/c++ programming

main() { int i=0; for(i=0;i<20;i++) { switch(i) case 0: i+=5; case 1: i+=2; case 5: i+=5; default i+=4; break; } printf("%d,",i); } } this is frm aptitude question....plz explain hw this works??? ...

C/C++, negation operator frustration

In the following code segment what will be the result of the function, value of x , value of y { unsigned int x=-1; int y; y = ~0; if(x == y) printf("same"); else printf("not same"); } Please explain how this works. From my side its answer will be "not same" but its actual answer is "same". ...

AIX 5.3 vs Solaris 5.10 - C strcat implementation

Does anyone have any idea of why this could happen? I have a C program in AIX 5.3, I've been asked to run it on a SPARC Solaris 10 machine, but when I did it, I noticed there was a buffer overflow with one of the many reckless strcat uses. My goal is not to sanitize the code but to provide a concrete and well founded answer of why does...

String reversal in C++

I am trying to reverse the order of words in a sentence by maintaining the spaces as below. [this is my test string] ==> [string test my is this] I did in a step by step manner as, [this is my test string] - input string [gnirts tset ym si siht] - reverse the whole string - in-place [string test my is this] - reverse t...

C: Regex library with MinGW

How do I install a C regex into MinGW? I'm using it's gcc... I'm running Windows XP. I prefer a updated one. Thank you. ...

Threads in userspace and yield

I am supposed to implement a userlevel threads library in C. To do so, I need to implement yield(), createThread() and destroyThread() functions. I believe I've got the basics right: To keep track of threads, I'll use a queue of ThreadControlBlock elements (which resemble PCBs in an OS) that look like this: struct ThreadControlBlock { ...

Changing certain byte in a packet stream

Hi guys, I am using C to implement a packet stream that will be sent out via wireless and am stuck at the following problem. I have an unsigned int 2 bytes long, in the following format in binary: XXXX YYYY XXXX XXXX, where X & Y's are bits. Looking at the format above, I need to just changed the YYYY bits and leave the other bits alon...

Is typedef'ing a pointer type considered bad practice?

Possible Duplicate: Typedef pointers a good idea? I've seen this oddity in many APIs I have used: typedef type_t *TYPE; My point is that declaring a variable of type TYPE will not make it clear that in fact a pointer is declared. Do you, like me, think that this brings a lot of confusion? Is this meant to enforce encapsula...

Determining the size of the next UDP datagram in system's queue

I want to know the size of the next UDP datagram in the system's queue. I found this question with a similar doubt, but using boost. The last answer (as of 2010/09/23) say something about using getsockopt with the SO_NREAD option in OS X, but I can't find anything about this with Windows (using Winsock). Here I found that I can use ioc...

Pointer alignment in libjpeg

From jmorecfg.h: #define PACK_TWO_PIXELS(l,r) ((r<<16) | l) #define PACK_NEED_ALIGNMENT(ptr) (((int)(ptr))&3) #define WRITE_TWO_PIXELS(addr, pixels) do { \ ((INT16*)(addr))[0] = (pixels); \ ((INT16*)(addr))[1] = (pixels)>>16; \ } while(0) #define WRITE_TWO_ALIGNED_PIXELS(addr, pixels) ((*(INT32*)(a...

Why does C++ not support Variable-length arrays?

Possible Duplicate: Variable length arrays in C++? I am just curious, is there any particular reason why C++ does not allow variable length arrays? ...

How can I convert (encode) RGB buffer to JPEG in plain C?

I would expect that there's some sort of library that I can use in this fashion: int* buffer[720*480]; // read in from file/memory/network stream raw_params params; params.depth = 16; params.width = 720; params.height = 480; params.map = "rgb"; params.interleave = JPEG_RAW_INTERLEAVE_OFF; jpeg_encode(buffer, params) But I can't seem ...

Fundamental typedef operand syntax

Given: typedef type-declaration synonym; I can see how: typedef long unsigned int size_t; declares size_t as a synonym for long unsigned int, however I (know it does but) can't see exactly how: typedef int (*F)(size_t, size_t); declares F as a synonym for pointer to function (size_t, size_t) returning int typedef's two operands...