c

How Can i convert a perl script into a C code?

How Can i convert a perl script into a C code? ...

Why I can't use unsigned short in switch/case?

I have two static member declarations in ClsA, like this: class ClsA { public: static unsigned short m_var1; static unsigned short m_var2; }; unsigned short ClsA::m_var1 = 1001; unsigned short ClsA::m_var2 = 1002; In ClsB, I use those static member declarations from ClsA like this: unsigned short var1; // assume var1 is declar...

C - curses keyboard doesn't work after def_prog_mode and reset_prog_mode, refresh

I am trying to go from my ncurses UI to an editor via a system call and then back again. With the help of several friendly programmers here, I learned how to use def_prog_mode and refresh to restore the state of my terminal UI after the user returns from the editor. So my code looks something like this: // save state and exit ui def_p...

C - retrieving elements from a list

I'm very new in C and right now I'm stuck with a simple problem. I want to retrieve the i'th element of the list and I have the following API. The argument 'sp' specifies the pointer to the variable into which the size of the region of the return value is assigned. const void *tclistval(const TCLIST *list, int index, int *sp); The lis...

Including C headers inside a C++ program

I have a C++ program (.cpp) inside which I wish to use some of the functions which are present inside the C header files such as stdio.h, conio.h, stdlib.h, graphics.h, devices.h etc. I could include the stdio.h library inside my cpp file as : #include <cstdio>. How do I include the other library files? How do I add the graphics.h libr...

Bus error on OSX - pthreads

Hi, am trying to get my head around the following: Have a small program am trying to port to OSX(intel) which calls function doWork() via pthread_create, in the function, I start by creating an array of long like such: long myarray[DIMENSION] on OSX, for the following values of DIMENSION, I get the following: 0->65434 = fine 6543...

wchar_t to octets - in C?

I'm trying to store a wchar_t string as octets, but I'm positive I'm doing it wrong - anybody mind to validate my attempt? What's going to happen when one char will consume 4 bytes? unsigned int i; const wchar_t *wchar1 = L"abc"; wprintf(L"%ls\r\n", wchar1); for (i=0;i< wcslen(wchar1);i++) { printf("(%d)", (wchar1[i]) & 255...

Best way to convert Unix time_t to/from abitrary timezones?

My code receives a time_t from an external source. However, that time_t isn't acutally based on UTC Epoch time, along with it I get a timezone string (eg, EDT, PST, etc), and its based on this offset'ed epoch. I need to convert this to a true UTC Epoch based time_t. Additionally, I need to be able to go in the opposite direction, taking...

Is this hack valid according to standard?

This is just like struct hack. Is it valid according to standard C? // error check omitted! typedef struct foo { void *data; char *comment; size_t num_foo; }foo; foo *new_Foo(size_t num, blah blah) { foo *f; f = malloc(num + sizeof(foo) + MAX_COMMENT_SIZE ); f->data = f + 1...

strcmp and wcscmp

Is this if( (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (wcscmp(FileData.cFileName, L".") != 0) && (wcscmp(FileData.cFileName, L"..") != 0) ) the same as this: if( (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && wcscmp(FileData.cFileName, L".") && wcscmp(FileData.cFileName, L"..") ) And also ...

Array starting point in C language

Possible Duplicate: Defend zero-based arrays Is it not possible for an array to start from 1. Why is it not possible for an array to start from 1 and why is the standard not getting revised to start the array from 1 ? ...

file format not recognized; treating as linker script

I am trying to run the C files downloaded from here as follows : gcc main.c docs_file.txt ksg_file.txt However, I receive the following error: /usr/bin/ld:docs_file.txt: file format not recognized; treating as linker script /usr/bin/ld:docs_file.txt:2: syntax error collect2: ld returned 1 exit status I am not sure what the problem ...

Font Metrics in C

I wanted to know if there is any library in C available for calculating the Font Metrics (Basically i wanted to know the width of a string of Particular Font). QT has QFontMetrics. Is there any way I can get similar data in C. ...

pthreads in C - pthread_exit

For some reason I thought that calling pthread_exit(NULL) at the end of a main function would guarantee that all running threads (at least created in the main function) would finish running before main could exit. However when I run this code below without calling the two pthread_join functions (at the end of main) explicitly I get a seg...

Need help understanding C program to find that machines IP address

I am not getting this assignment about finding the IP address of the machine. I need help understanding the logic of this code. Our college lab uses proxy server; will this code work on a computer without proxy? #include <stdio.h> /* stderr, stdout */ #include <netdb.h> /* hostent struct, gethostbyname() *...

How to speed up multidimensional array access in scipy.weave?

Hi All: I'm weaving my c code in python to speed up the loop: from scipy import weave from numpy import * #1) create the array a=zeros((200,300,400),int) for i in range(200): for j in range(300): for k in range(400): a[i,j,k]=i*300*400+j*400+k #2) test on c code to access the array code=""" for(int i=0;i<20...

program to find quadratic equation not giving true answer

#include<stdio.h> #include<conio.h> #include<math.h> void main(void) { int a,b,c; float d,d2; printf(" Enter a,b and c:"); scanf("%d %d %d",&a,&b,&c); d=b*b-4*a*c; if(d<0) { printf("(%d+i%d)/%d",(-b,sqrt(d),2*a)); printf("(%d-i%d)/%d",(-b,sqrt(d),2*a)); } else { printf("(%d...

Retaining Common Prefix of two strings.....C Programming... Segmentation fault error......

char *strip_postfix(char *str1, char *str2) { int i; for(i=0; str2[i] != '\0'; i++) { if(str1[i] != str2[i]) { str1[i] = '\0'; break; } } return str3; } This code, is giving segmentation fault error at line str1[i] = '\0' during run time..... I think there is some memory allocation i...

Conflicting types in a 2D array (C)

Hello, I am making my first C program, and it utilizes a 2D array, and the code seems weird to me. First, why do I have to store "White" in [1][6]? I tried [0][6], but the compiler complains and won't run but when I call it in printf, it's [0][6]. Also, when trying to store "Bl" in codes [2][6], it says conflicting type for codes. An...

Database or format for help system?

Hi. I'm implementing a help system for my app. Its written in C and Gtk+. Help is divided on books. Each book is just a bunch of HTML pages with resource. The problem I've encountered is that each book is ~30M (using WebKit Gtk port to display it). After zipping it becomes ~7M, but opening document becomes extremely slow :( So I'm think...