For the C code below, compare the defintions of the int pointers a and b;
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *a=malloc(sizeof(int));
int *b=(int *)malloc(sizeof(int));
return(0);
}
Is it better in any way to typecast the pointer of type void, returned by the malloc function?
Or is it auto-typecasted while...
Hi!
I am trying to call a C function sitting in a shared object from python, and using ctypes seems to be the best way of accomplishing this. I have to pass derived types to this function, with the following function prototype:
int MyFunc (Config *config, int *argc, char **argv )
The Config struct is defined as
typedef struct{ char ...
After all of this time, I've never thought to ask this question; I understand this came from c++, but what was the reasoning behind it:
Specify decimal numbers as you
normally would
Specify octal numbers by a leading 0
Specify hexadecimal numbers by a leading 0x
Why 0? Why 0x? Is there a natural progression for base-32?
...
Here's the current situation I'm in:
I want to distribute a binary app on Linux that would run on several distros (not all of them, just the main ones matter at the moment, let's focus on Ubuntu and Fedora for the sake of this discussion). The app in question links to libbz2 for some of its work. A simple "Hello World" will illustrate t...
I know this question has been asked time and again. I need random numbers between 0-9. I am using the following code:
srand(time());
int r;
for (;;)
{
while(condition)
{
r = rand()%10;
// ...
// ...
}
}
Now I am getting the same sequence of numbers for each iteration of for loop. Can someone provide...
Hello,
I have a text file that has strings on each line. I want to increment a number for each line in the text file, but when it reaches the end of the file it obviously needs to stop. I've tried doing some research on EOF, but couldn't really understand how to use it properly.
I'm assuming I need a while loop, but I'm not sure how to...
I have two questions related to memory. First some background. I am a novice-intermediate c programmer.
I have written several different tree like data-structures with variable number of nodes at each level. One such structure, can have as its data a number of integer variables, which themselves are primary data for integer trees. I ha...
I'm currently doing a project for a Beginner C programming class where i'm supposed to make a basic ordering system for a company.
I've got an issue with one of my functions, it works fine as a separate program but as a function in the ordering program it won't let me input a new item before it exits the function.
It seems however to ru...
I'm trying to define a system call that modifies the character buffer passed to it. Specifically, something like this:
...
asmlinkage int sys_mycall( char __user *buff, int len )
{
char tmp[1000];
copy_from_user(tmp, buff, len);
/* change tmp here */
copy_to_user( buff, &tmp, len );
}
Here, copy_to_user returns -1, and the...
I've read 'The C Programming Language', what should I be doing now? Is there anything important in C that's missed out in the book? Specifically interested in the Linux side of development, so is there anything important I should learn about C in Linux? (I already know some of the basics).
I'm sorry if this question seems a bit general...
Turn spoken dialogue into text-based, timecode-accurate, searchable metadata or just into text.
What do I need:
Open source libs
Articles on using them
...
Lets say I have a "Passenger" struct, which has a field for a name.
If I do (like the syntax of my book shows):
fread(&passenger, sizeof(Passenger), 1, in_fp);
printf("%s", (*passenger).first_name)
I get a segmentation fault, but if I do:
fread( (char *)passenger, sizeof(Passenger), 1, in_fp);
printf("%s", (*passenger).first_name)
...
I have an assignment in class that requires us to use POSIX threads and create n*(n-1)/2 of them to process a dataset of n elements.
You can think of it as basically the classical "handshake" in probability.
I know that for a large data set it's going to make the application CPU-bound and eventually it will spend so much time context s...
The linux server at my school is just a bare-bone server, no x-windows, just a command line interface.
I tried to make a graphical c program on that server but found much difficulties.
I use SDL library but every time compiling with gcc, it complains:
testcursor.c:(.text+0x1ad): undefined reference to SDL_Init'
testcursor.c:(.text+0x...
Hi. I am trying to understand some things about jump tables and its relationship between a switch case statement.
I was told that a jump table is a O(1) structure that the compiler generates which makes lookup of values essentially about as fast as you can get. However in some cases a Hashtable/Dictionary might be faster. I was also tol...
I wish to take a file encoded in UTF-8 that doesn't use more than 128 different characters, then move it to a 7-bit encoding to save the 1/8 of space. For example, if I have a 16 MB text file that only uses the first 128(ascii) characters, I would like to shave off the extra bit to reduce the file to 14MB.
How would I go about doing thi...
I'm really confused at the moment.
So I have 5 files: main.c, flight.c, flight.h, passenger.c, and passenger.h
flight.h has function prototypes for flight.c, and passenger.h has function prototypes for passenger.c
flight.c and passenger.c have definitions for these functions.
main.c is the program I'll interact with, calling function...
This is what I was given to start with.
int main(){
int a[5] = {0,1,2,3,4};
printf("Sum of elements of a: %d\n", calculate_sum(a,5));
return 0;
}
Here's what I've got, I don't know why it doesn't work, please help me.
#include <stdio.h>
int main()
{
int a[5] = {0,1,2,3,4};
int b;
...
Which, query performance wise, is more effective?
Considering T is a table, and PK is the primary key in the table T. Are they different or they are just a matter of choice?
select col1, col2 into :var1, :var2
from T
where PK = a
...or:
EXEC SQL DECLARE aCursor CURSOR FOR select col1, col2 into :var1, :var2 from T where PK = a...
I'm working with GNU assembler on i386, generally under 32-bit Linux (I'm also aiming for a solution under Cygwin).
I have a "stub" function:
.align 4
stub:
call *trampoline
.align 4
stub2:
trampoline:
...
The idea is that the data between stub and stub2 will be copied into allocated memory, along with a function poi...