Hi
I came across some codes in the following way
//file.c
#include <stdlib.h>
void print(void){
printf("Hello world\n");
}
and
//file main.c
#include <stdio.h>
#include "file.c"
int main(int argc, char *argv[]){
print();
return EXIT_SUCCESS;
}
Is there any flaw in this kind of programming style? I am not able...
Hi
I wrote this program for my homework (parallel programming), but I'm getting some errors on running.
This is the source:
/****************************************
* Program: *
* ALL_TO_ALL_BROADCAST_MESH *
* *
* Author: *
* ------------------- *
* ------------------- *
***************...
On 'C', Linux,
Do I need static libraries to statically link, or the shared ones I have suffice?
If not, why not? (Don't they contain the same data?)
...
I'm starting to learn C by reading K&R and going through some of the exercises. After some struggling, I was finally able to complete exercise 1-19 with the code below:
/* reverse: reverse the character string s */
void reverse(char s[], int slen)
{
char tmp[slen];
int i, j;
i = 0;
j = slen - 2; /* skip '\0' and \n */
tm...
I've been looking for a way to get the terminal width from within my C program. What I keep coming up with is something along the lines of:
#include <sys/ioctl.h>
#include <stdio.h>
int main (void)
{
struct ttysize ts;
ioctl(0, TIOCGSIZE, &ts);
printf ("lines %d\n", ts.ts_lines);
printf ("columns %d\n", ts.ts_cols);
}
...
Say I have a pointer to a function _stack_push(stack* stk, void* el). I want to be able to call curry(_stack_push, my_stack) and get back a function that just takes void* el. I couldn't think of a way to do it, since C doesn't allow runtime function definition, but I know there are far cleverer people than me here :). Any ideas?
...
It seems to me that Linux has it easy with /proc/self/exe. But I'd like to know if there is a convenient way to find the current application's directory in C/C++ with cross-platform interfaces. I've seen some projects mucking around with argv[0], but it doesn't seem entirely reliable.
If you ever had to support, say, Mac OS X, which do...
Hello,
I have a public function that needs to check the validity of a few parameters, but this function is also used internally in a few others places in which I know that the given parameters will be valid. Thus, I'm wondering, which is more costly: 1) Leave the validity checks in every public function, or 2) Do the validity checks in...
I was wondering if anyone would be so kind as to look at this code I've written for practice. Besides a little php, c if my first language and I'm trying to teach myself. so pretty much, what am I doing wrong, where can I optimize, anything.
What this code does is (in terminal) draw a bunch of random 1's and 0's, but I added an effect k...
I am writing a system-critical program for a Linux distribution that I am developing. It needs to restart itself on receiving certain signals, to try to avoid crashing. The problem is, after the restart, I cannot re-enable that signal. That is, the signal cannot be received twice. After execv()'ing itself, when the new process calls sign...
I need to examine a gif image in a C program. I looked into the FreeImage library but I can't figure it out. Could someone give an example of using FreeImage to get into all the little details about a gif image such as frames, background, transparency, etc... And how to increment through the frames and get the animation's current image/p...
How do I allocate memory for a char variable (not a char pointer) inside a struct?
(Variable names are in portuguese, sorry if it's kinda confusing)
I have this struct:
typedef struct node{
char rotulo[10], instrucao[1][2][10], flag;
int simplificado;
struct node *referencias[2];
struct node **antecessores;
int n...
As my formal education in programming pre-dates C, I learnt C from K&R and other texts.
Are there helpful conventions for vocalising C code when reading and writing it?
For example, in
d = emalloc(sizeof(*d));
d->d_name = estrdup(name);
is '=' best read as 'is set to' or 'equals' or something else?
Would '==' then be read as 'equ...
Hi, I am writing a file splitting program, to assist with using large files with iPod notes. I want to use tmpfile() in cstdio but it returns a file* not an fstream object. I know it's not possible in standard C++ but does anyone know any libraries that work well with the standard that have the ability to convert a FILE* to an std::fstre...
Hi All,
I'm looking for a function to allow me to print the binary representation of an int. What I have so far is;
char *int2bin(int a)
{
char *str,*tmp;
int cnt = 31;
str = (char *) malloc(33); /*32 + 1 , because its a 32 bit bin number*/
tmp = str;
while ( cnt > -1 ){
str[cnt]= '0';
cnt --;
}
cnt = 31;
while (a >...
I need a multidimensional array of chars that is dynamic in only one dimension...
I have to store a pair of strings with a length of 10 (or less) chars each, but with a variable number of "pairs".
My idea was this
char (*instrucao)[2][10];
Which gives me a pointer to a 2x10 array of chars, but this is not working properly when i do s...
I'm going though a computers system course and I'm trying to establish, for sure, if my AMD based computer is a little endian machine? I believe it is because it would be Intel-compatible.
Specifically, my processor is an AMD 64 Athlon x2.
I understand that this can matter in C programming. I'm writing C programs and a method I'm usin...
I want to access functions within a DLL using Ruby. I want to use the low-level access of C while still retaining the simplicity of writing Ruby code. How do I accomplish this?
...
I want to write a library which will be dynamically linked from other programs running on modern operating systems like Windows, Linux and OS/X (i.e. it will be deployed as a .dll or .so module).
What is the most appropriate language in that case? Should I stick with plain C? Or is C++ also ok?
...
I am using WinHTTP (WinAPI interface) in a C program. When I'm running the relase build from outside the ide (that is, without any debugger. IDE is VS2008) it works fine.
However, if I run it inside the debugger (either the release or the debug build), or if I run the debug build from outside, WinHTTP won't work right.
The status callb...