2
голосов
8ответов
532 просмотров

Please explain this behavior with character arrays/strings in C

I get this when I was trying something (just for understanding). Please explain this behavior: First attempt: void main() { char src[] = "vinay"; int i; // char name[5] = "test"; char *name= "abcde"; printf("%s \n", name); if (*(name+5) == 'abcde 6th char is n...

9
голосов
2ответов
1367 просмотров

Marking library functions as deprecated/unusable without modifying their source code

I have a large codebase that uses a number of unsafe functions, such as gmtime and strtok. Rather than trying to search through the codebase and replace these wholesale, I would like to make the compiler emit a warning or error when it sees them (to highlight the problem to maintenance developer...

42
голосов
5ответов
44175 просмотров

C struct initialization using labels. It works, but how?

I found some struct initialization code yesterday that threw me for a loop. Here's an example: typedef struct { int first; int second; } TEST_STRUCT; void testFunc() { TEST_STRUCT test = { second: 2, first: 1 }; printf("test.first=%d test.second=%d\n", test.first, t...

0
голосов
3ответов
205 просмотров

identify the exact header file

I am using some macro in my source file (*.c ) . Is there any way during compilation or from the library that I can identify the exact header file from which this particular macro is getting resolved ? The issue is we are using a macro #defined to 10 in some header file, but the value being re...

0
голосов
1ответов
390 просмотров

GTK List with images and Text and other widgets

I am building a simple chat application under GTK+ and C, In that i need to display List of contacts like follows. 1. Window Containing contact list with contacts Presence and status Icons and name. +-----------------------------------------+ | [PresenceImage1] [Name1] [StatusImage1] | | [Prese...

1
голосов
4ответов
2434 просмотров

Putting strings into a 2D chararray in C

How do I put strings into an 2D char array from (for example) a file? char buffert[10][30]; int i = 0; while(!feof(somefile)) { fscanf(somefile, "%s", temp); buffert[i][] = temp; i++; } This will not do it.

4
голосов
2ответов
2387 просмотров

Unwanted sal.h warnings

I'm trying to use VS 2008 for compiling some C code. I configured the project to use ANSI C standard without any language extensions. I also upped the warning level from 3 to 4. Upon building the project I always get this warning: c:\program files\microsoft visual studio 9.0\vc\include\sal.h(10...

2
голосов
2ответов
2809 просмотров

Fast Multiplication

I'm writing code for a microprocessor with fast integer arithmetic and not so fast float arithmetic. I need to divide an integer by a number from 1 to 9 and convert result back to integer. I made a float array with members like 0, 1, 0.5, 0.3333 etc. But i think there is MAGIC constants (like 0x...

14
голосов
7ответов
5067 просмотров

Visual C++ standards compliance

I was wondering if, and to what degree, does Microsoft's Visual C++ compiler conform to the current C (C90/C99) and C++ (ISO/IEC 14882:2003) standards. Unfortunately I'm only able to find partial information on the subject, I may be looking at all the wrong places. Any pointers to related resour...

0
голосов
3ответов
1063 просмотров

MySQL C API custom values

I have been working with the tutorial on MySQL C API from http://zetcode.com/tutorials/mysqlcapitutorial/ the following example is working fine: #include <my_global.h> #include <mysql.h> int main(int argc, char **argv) { MYSQL *conn; conn = mysql_init(NULL); mysql_real_connect(con...

21
голосов
7ответов
35120 просмотров

C read binary stdin

I'm trying to build an instruction pipeline simulator and I'm having a lot of trouble getting started. What I need to do is read binary from stdin, and then store it in memory somehow while I manipulate the data. I need to read in chunks of exactly 32 bits one after the other. How do I read in c...

1
голосов
2ответов
857 просмотров

MapViewOfFile with pointers between threads

I have some programs that use MapViewOfFile to share data, but I am getting strange access violations that seem to be from accessing the mapped file data. Some of the shared data has pointers, however these pointers are only set and used by one process, but by several threads within the process....

24
голосов
7ответов
9573 просмотров

Is there a standard function in C that would return the length of an array?

Is there a standard function in C that would return the length of an array?

3
голосов
1ответов
964 просмотров

gtk composite widget focus

I created a composite widget with webkit_webview widget stored in scrollwed window with a gtkvbox base widget. How do make to so the base gtkvbox widget is in focus whenever any of the contained widgets have focus? Specifically, I am trying to add accelerator that should only be active when the c...

15
голосов
3ответов
8307 просмотров

Duplicate file descriptor with its own file offset

How can one create a new file descriptor from an existing file descriptor such that the new descriptor does not share the same internal file structure/entry in the file table? Specifically attributes such as file offset (and preferably permissions, sharing and modes) should not be shared between ...

0
голосов
4ответов
492 просмотров

Gtk per widget accelerators

I build a composite widget and would like it to have it's own accelerators (hotkeys) available only when it is in focus. The only Idea I have so far of how to accomplish this is to change out the accelerator group in the top level when ever my widget goes in and out of focus. It seems like there ...

5
голосов
3ответов
1016 просмотров

How do I check if a value matches a string

I have a struct here with something like: char *sname; ........ players[i].sname equalling "James". I need to check for equality between values like so: if (players[i].sname == 'Lee') but am not having much luck. Is there a str* function I should be using or is there anyway to fix up my i...

13
голосов
2ответов
13450 просмотров

emacs, etags and using emacs as an IDE

My usual tools are Emacs with g++ on a Linux system to implement my research algorithms. For the last some years, I have used emacs in a fairly basic way. I open C or C++ files, edit them with a syntax highlighting scheme of my choice and compile and do other stuff from within emacs (or maybe fro...

0
голосов
1ответов
1988 просмотров

How do I go about Flushing STDIN here?

I have a function (in C) that gets input from the user, (using scanf) stores it in an unsigned int, and returns the input to other functions that handle it: unsigned int input(void) { unsigned int uin; scanf("%u", &uin); return val; } I was wondering, being as I ought to flush...

35
голосов
4ответов
155728 просмотров

Iterate through a C array

I have an array of structs that I created somewhere in my program. Later, I want to iterate through that, but I don't have the size of the array. How can I iterate through the elements? Or do I need to store the size somewhere?

18
голосов
3ответов
3638 просмотров

Verifying that C / C++ signed right shift is arithmetic for a particular compiler?

According to the C / C++ standard (see this link), the>> operator in C and C++ is not necessarily an arithmetic shift for signed numbers. It is up to the compiler implementation whether 0's (logical) or the sign bit (arithmetic) are shifted in as bits are shifted to the right. Will this c...

2
голосов
1ответов
1816 просмотров

Is IAR assembler possible to import #define from C header to assembler?

I have a mixed assembler and C project based on IAR ARM. I have some #define in C header, I like to use (import) them in assembler file. Could anybody tell me it is possible? Many thanks.

4
голосов
3ответов
1229 просмотров

Bit shifting in internet checksums

This is almost certainly a very silly question, but for some reason I'm having trouble with internet checksum calculations. All of the algorithms basically look something like this: WORD chksm(WORD *startpos, WORD checklen){ ulong sum = 0; WORD answer = 0; while (checklen > 1) { sum += ...

139
голосов
10ответов
132040 просмотров

What happens to a declared, uninitialized variable in C? Does it have a value?

If in C I write: int num; Before I assign anything to num, is the value of num indeterminate?

16
голосов
4ответов
36662 просмотров

Hide console in C system() function, Win

I am coding a C program in Dev-C++, and I need to use a couple of Windows (CMD) commands. It is easy, but when the command in the system() function is executed, the program runs the console in the execution. An example: #include <stdio.h> #include <stdlib.h> #include <windows.h&g...

0
голосов
2ответов
1359 просмотров

Reading a line from a socket

I am writing some code in which i need to get a line from a socket whenever the line ends in a newline or carriage return. The line shoould be stored in a buffer. n = recv(sock, &ch, 1, 0); if (n > 0) { if (ch == '\r') { // do stuff } // } // I am using co...

107
голосов
2ответов
61724 просмотров

Creating C macro with ## and __LINE__ (token concatenation with positioning macro)

I want to create a C macro that creates a function with a name based on the line number. I thought I could do something like (the real function would have statements within the braces): #define UNIQUE static void Unique_##__LINE__(void) {} Which I hoped would expand to something like: static ...

2
голосов
3ответов
1305 просмотров

Translating C code using OpenSSL for public-key authentication to VisualBasic.NET using system.security.cryptography?

I am trying to mimic the results of some C code that uses the OpenSSL library using the system.security.crytography library in the .net 3.5 world, and I can't seem to get it right. I need some help... part of the issue is my understanding of crytography in general. Here's what is supposed to ha...

6
голосов
2ответов
2455 просмотров

How to pass a function pointer to a function with variable arguments?

I don't know how to accomplish this! how to get the function pointer in va_list arguments? thanks so much.

2
голосов
3ответов
448 просмотров

Handling CGI requests in a bare-bones http server

I am writing a basic http server in C. Handling a simple static .html file is easy but I have no idea how to handle dynamic .pl .cgi file extensions. I know I will have to use exec() but how is my question?