c

How to correctly allocate memory for a structure in a function to return its value for later use and how to cast a structure into a pointer?

I'm currently self-studying C for mastering an university project. In that project we have several signatures given that we need to implement for solving our task. After several hours of trying to make some progress, I must admit that I'm totally confused about the return types of functions. I will show you some code: This is a structur...

Is it a common practice to re-use the same buffer name for various things in C?

For example, suppose I have a buffer called char journal_name[25] which I use to store the journal name. Now suppose a few lines later in the code I want to store someone's name into a buffer. Should I go char person_name[25] or just reuse the journal_name[25]? The trouble is that everyone who reads the code (and me too after a few week...

How to qsort an array of pointers to char in C?

Suppose I have an array of pointers to char in C: char *data[5] = { "boda", "cydo", "washington", "dc", "obama" }; And I wish to sort this array using qsort: qsort(data, 5, sizeof(char *), compare_function); I am unable to come up with the compare function. For some reason this doesn't work: int compare_function(const void *name1,...

polymorphism in c and buffers

I have this union: typedef union Message { message_base base; message_with_parameters parameters; reply_message reply; buffer_t *buffer; // can't figure out what to put here } message; message_with_parameters has a message_base as the first field and reply_message has a message_wit...

c: printf("%-16llu", my_var);

It's been awhile since I've played with c, and now I find something I've never seen before: printf("%-16llu", my_var); It would seem to be saying print 16 characters of a long unsigned int. But, what's the second 'l' for? long long? ...

difference betweent printf and gets

Hi, I am beginner for programming.I referred books of C programming,but i am confused. 1.) What's the difference betweent printf and gets? I believe gets is simpler and doesn't have any formats? ...

Multidimensional array

How to get stored the value entered by user in multidimensional array ...

ordering of functions

I want to know the ordering of functions in a given source file (and ultimately which header files they correspond to), for purposes of knowing the ordering of lib includes. Is there a "canonical" automated way (i.e. not trial and error) to get this info? I'm good with sed/awk hacks but is there a "better way"? ...

Finding the sum of the digits

I've have a 5 digit integer say, int num = 23456 how to find the sum of the digits.??? ...

Cross-Compiling gcc

I am following the instructions here for cross-compiling GCC. I am on a mac. When I run this command from the gcc source folder: ./configure --target=i586-elf --prefix=/usr/local/cross --disable-nls --without-headers --enable-languages=c,ada,c++,fortran,java,objc,obj-c++,treelang I get this error: configure: error: GMP 4.1 and MPFR 2.2.1...

points as function parameters C

this is probably a simple solution I am not that familiar with C just trying to port my java data structure assignments to C. this is the error i am getting: test.c:4: error: expected ‘)’ before ‘*’ token test.c:11: error: expected ‘)’ before ‘*’ token #include <stdio.h> #include <stdlib.h> void to_screen(NODE *cur){ while(cur->...

Connecting to MS SQL Server from a cross-platform application

I am working on a GUI application that will be used to perform "manual assessment" of large datasets produced by an AI algorithm. The nature of the assessment isn't important to this question; only the fact that the program will need to periodically check for new data from a server, download it, and then upload the results that the user ...

C getopt -<integer>

How do I get the option -10 from command line arguments- "tail -10". getopt function finds '1' character. But how do I access the string "10"? If this can be done by getopt_long, an example would help. Thanks. ...

How do I handle this pointer in getaddrinfo?

Warning: Please treat me like the rookie I am. This is my first "real" C program. So if I don't understand some things, that's why. I'm trying to make a chat server following the example from Beej's Guide to Network Programming. It came recommended, so there you go. I want to have a function accept a pointer to a structure, modify prop...

Floodfill replace with GDI?

My application has a static control which inside has a tab control. It looks like this: and I want to handle the topbar's paint event so that after it has drawn itself (and its children), have it floodfill to look more like this: Given that I'v subclassed the topbar and can override any of its events, how could I do this? Thanks ...

How to Make fullscreen & colouring the program output?

This is a program like Screensaver. How to Make fullscreen & colouring of the program output? and automatic exit program on mouse move? #include<windows.h> #include<stdio.h> #include<time.h> #include<math.h> struct tm *local(){ time_t t; t = time(NULL); return localtime(&t); } const char *ClsName = "BitmapLoading"; cons...

Code for directory monitor using Unix concepts in C language

On a server, a process monitors the files in a Unix file system. If a client sends the file name to be monitored, the server has to send the report to the client whether that file got changed or deleted. For server-client communication, we should use either message queues or sockets. For every change in the file, the server has to not...

Why MSVC generates warning C4127 whan constant is used in "while" - C

For code, while(1) { /* ..... */ } MSVC generates the following warning. warning C4127: conditional expression is constant MSDN page for the warning suggests to use for(;;) instead of while(1). I am wondering what advantage for(;;) is giving and why it warns for the constant usage in while? What flag to use on GCC to get the ...

Why time keeps on varying?

I executed one program and when I calculated the time elapsed I found that time is not constant. It's varying under some range. I wanted to know why is it so? ...

changing the index of array

hi, so far, i m working on the array with 0th location but m in need to change it from 0 to 1 such that if earlier it started for 0 to n-1 then now it should start form 1 to n. is there any way out to resolve this problem? ...