c

is there are nice unix command for dumping the text representation of a binary file.

Hi I got some binary files containing integers. Is there some nice unix command, that will allow me to dump it to a terminal without offset info etc? something like double int[4]; while(fread(tmp,sizeof(int),4,stdin)) for(int i=0;i<4;i++) printf("%d\t",tmp[i]); It seems that hexdump and od gives me the information I want, but t...

Is there a way to identify version of c/c++ library?

For example, how to get the version of /usr/lib/libz.a? It will be great if other useful information such as compiler/arch etc. can be fetched. The reason I want to know this is that gcc always say it ignored the libz I offered in command line when I compile my program and linked with specific versioned libz. gcc think the /usr/lib/libz...

Why does it NOT give a segmentation violation?

The code below is said to give a segmentation violation: #include <stdio.h> #include <string.h> void function(char *str) { char buffer[16]; strcpy(buffer,str); } int main() { char large_string[256]; int i; for( i = 0; i < 255; i++) large_string[i] = 'A'; function(large_string); return 1; } It's compiled and ...

strstr matching first occurrence in c

I was wondering how could I match the string "Just" in str1 if str1 contains the strings as: "this is Just/1.1.249.4021 a test" // "Just" will always be the same I'm trying to match it using strstr but so far it won't match because of the /... Any suggestions on how to match it? Thanks ...

Any difference between these two while loops?

while ((R_SPI2SR & B_SPIF) != B_SPIF) { SERIAL_SERVICE_WDOG; }; while ((R_SPI2SR & B_SPIF) != B_SPIF) { SERIAL_SERVICE_WDOG; } I like to know what is the purpose in putting semicolon.. ...

string representation of enum values

Hello, gcc 4.4.2 c89 I have the following enum: enum drop_options_e { drop_ssm, drop_snm, drop_ssb }; I am just wondering that is the best way to get the string representation value from the enum. So basically, instead of returning the value of 0 for drop_ssm, I could get the 'drop_ssm' instead. Many thanks for any adv...

how to write unicode hello world in C on windows

im tyring to get this to work: #define UNICODE #define _UNICODE #include <wchar.h> int main() { wprintf(L"Hello World!\n"); wprintf(L"£안, 蠀, ☃!\n"); return 0; } using visual studio 2008 express (on windows xp, if it matters). when i run this from the command prompt (started as cmd /u which is supposed to enable unicode ?...

How to link pnglite library in c?

Hi, I installed from kubuntu's package management this handy pnglite library. It contains just one header file "pnglite.h" and one object file "pnglite.o". I have found out where those files are, but I don't know how to link them. I'm using netbeans, but don't know how to link them in there. Also I don't understand how to link them at c...

"Parse error" in struct declaration

I want to use some basic struct in C like the following: struct p { int a; int b; p * next; } However, it fails to compile with an error: parse error before "p" on the line with p * next;. Do you have any idea what the reason could be for this problem? ...

How to write a buffer-overflow exploit in GCC,windows XP,x86?

void function(int a, int b, int c) { char buffer1[5]; char buffer2[10]; int *ret; ret = buffer1 + 12; (*ret) += 8;//why is it 8?? } void main() { int x; x = 0; function(1,2,3); x = 1; printf("%d\n",x); } The above demo is from here: http://insecure.org/stf/smashstack.html But it's not working here: D:\tes...

Constraint to array dimension in C language

int KMP( const char *original, int o_len, const char *substring, int s_len ){ if( o_len < s_len ) return -1; int k = 0; int cur = 1; int fail[ s_len ]; fail[ k ] = -1; while( cur < s_len ){ k = cur - 1; do{ if( substring[ cur ] == substring[ k ] ){ fail[ cur ] = k; break; }else{ ...

lseek/write suddenly returns -1 with errno = 9 (Bad file descriptor)

My application uses lseek() to seek the desired position to write data. The file is successfully opened using open() and my application was able to use lseek() and write() lots of times. At a given time, for some users and not easily reproducable, lseek() returns -1 with an errno of 9. File is not closed before this and the filehandle (...

Why touching "d_name" makes calls to readdir() fail?

Hi, I'm trying to write a little helper for Windows which eventually will accept a file extension as an argument and return the number of files of that kind in the current directory. To do so, I'm reading the file entries in the directories and after getting the extension I'd like to convert it to lowercase to compare it with the yet-to...

OpenCV: Traincascade fails "Assertion failed _img.cols == winSize.width"

Anybody has an idea what OpenCV Error: Assertion failed _img.cols == winSize.width means? I'm not familar with the new implemenation of the haar training (=traincascade) nor could I find any documentation in the wiki. Thanks, Josef ...

Is the following C code safe?

#include<cstdio> #include<stdlib.h> int main() { char* ptr=NULL; printf("%s",ptr); return 0; } It prints (null) as output. The above is a sample code. In real code i get char* as a return of a function and i wish to print the character string for logging. However, NULL is also a valid return value of that function and so i...

in c, how to change text on ThunderRT6UserControlDC btn

I get a handle to ThunderRT6UserControlDC button which in terms has two children of type ThunderRT6Timer (though I am not sure what these timers are for) The ThunderRT6UserControlDC window looks like a button but has no caption set (verified via spy++). When sending SetWindowText from within the same process, the caption changes (verif...

Structuring Win32 GUI code

I wish to improve my code and file structure in larger Win32 projects with plenty of windows and controls. Currently, I tend to have one header and one source file for the entire implementation of a window or dialog. This works fine for small projects, but now it has come to the point where these implementations are starting to reach 100...

C + GUI + Mac OS

i know c and I want to develop applications with GUI for Mac OS. Where do I start? ...

Can you tune C runtime heap segment reservation size on XP?

When the VC6 C runtime on XP can't serve an allocation request within an existing heap segment, it reserves a new segment. The size of these new segments increase by factors of 2 (until there are not large enough free areas to do that, at which point it falls down to smaller segments.) In any case, is there any way to control this behav...

Pass a dynamic structure by reference? [C]

BIG EDIT: Ok, my original question didn't help me. Here is a second go. My struct looks like this: struct node { char *name; int age; struct node *nextName; struct node *nextAge; }; I have to make two linked lists out of structures like this,. So i have 'rootAges' which keeps track of where the Age-based list starts an...