c

including header file

hello everyone, I have some question about header files(I'm talking about c, but I think it will be the same for c++), let's assume I have some my_ADT.c file (inside I have implementation of the functions and actual struct) and also my_ADT.h inside I have pointer for my struct Question: if I use ADT Set for implementation my_ADT do I nee...

Why is the difference between an expression and a statement

Possible Duplicate: Expression Versus Statement What does expression mean? Something that evaluates to something, returns a value? How is it different from a statement. Can a statement contain an expression and vice versa? ...

problems with typedef on C

I writing some ADT on C: I have two file date.c and date.h inside date.c I have: typedef struct Date_t { int date; char* month; int year; } Date; inside date.h I have: typedef Date pDate; compiler gives me errors: ..\checking.h:15: error: syntax error before "pDate" can somebody please explain what is wrong with my typedef, ...

Deleting duplicates in the array

I made a program to delete duplicates in an array but the program's if condition always remain true. I understood what the problem was,changed arr[i] to arr[count] and allocated memory via malloc,but the program prints the array as it is without deleting the duplicates. # include<stdio.h> # include<stdlib.h> int count=0; ...

Passing file pointer into functions, and file not being read correctly.

I think my problem with my code that the file is not being passed correctly. The input is a file with three lines 1 2 3; 4 5 6; 7 8 9; and the output is a Segmentation fault (core dumped), the output is supposed to print the first line 1 2 3. #include <stdio.h> #include <stdlib.h> int getNum(); int getLine(); int getMatrix(); int det1(...

Binary Tree, C language

the code is here: http://pastebin.com/9vswg7b0 here is an possible input: Inserir Jose 30264221 15 Inserir Carlos 304 1 Inserir Maria 887745 7 Inserir Paulo -147 -8 Inserir Isabel 7845 38 Inserir Ana 4578 5 Inserir Danilo 5474 4 Inserir Jose 3641 36 Inserir Pedro 1234 1 Remover 4 Remover 1 Remover 12 Buscar 14 Buscar 5 Imprimir in F...

pass static variable between two files in C/C++

Hi, I have a question to ask about passing static variables between two files. Now I have one file A.c and a second file B.cpp In A.c static struct { int int } static_variable Now A.c has to call a function func() in B.cpp, and this function has to modify the static_variable in A.c In B.cpp func() { static_variable =...

understanding this opengl code

I'm a Java programmer, learning opengl in C for the first time. I wanna dissect this simple code that my instructor gave me without much explanation: void renderScene (void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glVertex3f(-0.5,-0.5,0.0); glVertex3f(0.5,0.0,0.0); glVertex3f(0.0,0.5,0.0); ...

Find the sum of all the multiples of 3 or 5 below 1000.

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. I have the following code but the answer does not match. #include<stdio.h> int main() { long unsigned int i,sum=0; clrscr(); for(i=0;i<=1000;i++) { if((i%5==0)||(i%3==0)) { ...

Passing 2D arrays in C

I took a hiatus from C and am just getting back into it again. If I want to create a 2D array of doubles, I can do it two ways: double** m_array = (double**) malloc(2*sizeof(double*)); double* m_array = (double*) malloc(2*sizeof(double)); OR double array[2][2]; But, when I wish to pass the malloc'd array versus passing the other...

Finding matching IPv6 addresses based on an input string.

Hi, I need some help with finding network interfaces based on a provided IP address. I need a cross-platform way to reliably find the local interface that has the given address in both IPv4 and IPv6 formats. I created the attached program to take an IP address as a string and search through the results of getifaddrs. The reason is th...

compare an array of enums in (Objective) C

I want to test for transition from one state to another. I have defined my states in an enum like this: enum FingerStatus { FINGERS_UP, MOVING, FINGERS_STILL }; I have a "currentState" and a "newState" variable. I know that enums are just integers, and if they're 16-bit integers, which I think they are, it's possible to represent two ...

Hardware FPU error from ld when linking with .a archive

I have a strange problem that I can't seem to solve. I'm developing in C/assembly on an embedded ARM board with no FPU, and using GCC's soft floats. Everything is compiled with -msoft-float as a CFLAG I'm trying to make an .a library in one directory and link with my kernel. When I do so, I get an error from ld: ERROR: lib/libfoo.a(s...

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... I made the program but my answer doesnt match. #include<stdio.h> int main() { long unsigned int i,sum=0,x=1,y=2,num; for(i=0;i<4000000;i++) { num=x+y; ...

Semaphores and concurrent programming

Hello. For a homework assignment i need to program the following scenario. This is going to be done using semaphores using BACI (which is C--) There are 2 unisex restrooms that can hold 4 people each. Since it is unisex only people of the same sex can be in the restroom at the same time and FIFO is not important. I have the basic "al...

Background process is exiting faster than I can add its pid for management.

I'm creating background processes in C using fork(). When I created one of these processes, I add its pid to an array so I can keep track of background processes. pid = fork(); if(pid == -1) { printf("error: fork()\n"); } else if(pid == 0) { execvp(*args, args); exit(0); } else...

C - Parsing a command line with an unknown number of parameters

Possible Duplicate: Parse string into argv/argc I'm trying to write a fake shell using C, so I need to be able to take a command and then x number of arguments for the command. When I actually run the command, I'm just using execvp(), so I just need to parse the arguments into an array. But I wasn't really sure how to do this ...

Managing an array of indeterminate type with void pointers

I'm trying to write my own Mergesort function in the same fashion as C's qsort function. If I were writing MergeSort for an array of known items, I wouldn't have a problem, but since I don't know what they'll be it's throwing me for a loop. The specification given by my professor didn't want me to use a separate function for merging, so...

[MinGW] gcc: CreateProcess: No such file or directory

Hello, I am getting this error whenever I try to run GCC outside of it's installation directory (E:\MinGW\bin). So, lets say I am in E:\code and have a file called one.c. Running: gcc one.c -o one.exe will give me this error: gcc: CreateProcess: No such file or directory The only workaround is to navigate to it's installation direc...

Data Alignment with network programming

I'm a little confused regarding data alignment. On x86, we typically take alignment for granted. However, I'm programming on a system that is very strict and will error out if I try to access unaligned data. Heres my problem: First, I'm going to show you some structs I have: struct sniff_ethernet { u_char ether_dhost[6]; /* Destinat...