c

Different char type in windows programming

Hi all Recently, I meet some tasks about the char/string on windows platform. I see that they are different char type like char, TCHAR, WCHAR, LPSTR, LPWSTR, LPCTSTR. Can someone give me some information about it? And how to use like the regular char and char *. I cam confused about these types? Best Regards, ...

Why this code below fails

#include <stdio.h> int *top; int a=1; top=&a; void main() { printf("%d\n",*top); } error C2440: 'initializing' : cannot convert from 'int *' to 'int' UPDATE I know how to make it work,but I'm asking why it DOESN'T work. ...

passing 2d arrays

Can anyone tell me how can we pass a 2d array to a function in c so that its data dont get lost.Please explain with example. Thanks in advance ...

What is the difference between a String Constant and String Literal in C?

What's the difference between a String Constant and String Literal in plain C? This question is similar to another: http://stackoverflow.com/questions/25746/whats-the-difference-between-a-string-constant-and-a-string-literal ...except that one was regarding Objective-C (using NSString) and not C. ...

Converting char to int

I've written a very simple program that is meant to covert a char to its equivalent ASCII value (eg. A = 65), but I'm getting no output at all. where am i going wrong? Program: test.c #include<stdio.h> int main() { char test = 'c'; int key = (int)(test); printf("%d",key); return 0; } Bash script to compile and run gcc -o te...

Dynamic allocation with scanf()

My question is exactly the same as this one. That is, I'm trying to use scanf() to receive a string of indeterminate length, and I want scanf() to dynamically allocate memory for it. However, in my situation, I am using VS2010. As far as I can see, MS's scanf() doesn't have an a or m modifier for when scanning for strings. Is there any ...

What's the point of this series of C typedef/struct/union/enum definitions?

Inside of this first step towards a bootstrapped scheme interpreter I find the following set of typedef, struct, union, and enum definitions: typedef enum {FIXNUM} object_type; typedef struct object { object_type type; union { struct { long value; } fixnum; } data; } object; In particular, I'm ...

Comparing characters in c?

The following code snippets are from a c program. The user enters Y or N. char *answer = '\0'; scanf (" %c", answer); if (*answer == ('Y' || 'y')) //do work I cant figure out why this if statement doesn't evaluate to true. I checked for the y or n input with a printf and it is there so I know im getting the user input. Al...

Predict the number

I want the user to enter a 4 digit number and the program must tell what that 4 digit number was i.e generate that 4 digit number by Brute force attack.But at the line mentioned below the compiler says invalid indirection.I would also like to have some comments about they way I am implementing it,is it a good practise? #include<stdio.h>...

Getting pagefile.sys' handle

How to use createfile api open pagefile.sys and get it's handle ? How does pagedfrg.exe tool open pagefile.sys and get it's file cluster info? I want to using FSCTL_QUERY_RETRIEVAL_POINTERS to get this file's cluster info. The intent is to send strictly this FSCTL to analyze the used clusters for statistical purposes. ...

buffer becomes NULL after reindexing

#include <stdio.h> #include <stdlib.h> char *color[] = { /*0*/"red||bluegreen", /*1*/"blue", /*2*/"green", "\0" }; int fun1(char * str1) { int c = 0; while(1) { if(str1[c] == '|' && str1[c+1] == '|') return c; c++; } return 0; } 1. int main() 2. { 3. int ret...

Referencing a typedef as its struct counterpart.

Ok guys, we all know there are all lot of typedef/struct questions out there, but I feel this one is a bit of a mind bender. I'm simulating the neighbor interactions of a crystal lattice using strictly C. I have a struct called "ball_struct" which I typedef'ed as just "ball". The struct contains a pointer to a list of ball_structs (sin...

Different cases for exception occuring in C, C++

Currently I need to fix exceptions occurring in the code. Could someone specify various points like in what cases or when do exceptions occur in C, C++ languages. and what is the best approach to handle exceptions in C, C++ languages. ...

Check if a number is non zero using bitwise operators in C.

Check whether a number x is nonzero using the legal operators except !. Examples: isNonZero(3) = 1, isNonZero(0) = 0 Legal ops: ~ & ^ | + << >> Note : Only bitwise operators should be used. if, else, for, etc. cannot be used. Edit1 : No. of operators should not exceed 10. Edit2 : Consider size of int to be 4 bytes. int isNonZero(...

How do I extract all the data from a bzip2 archive with C?

I have a concatenated file made up of some number of bzip2 archives. I also know the sizes of the individual bzip2 chunks in that file. I would like to decompress a bzip2 stream from an individual bzip2 data chunk, and write the output to standard output. First I use fseek to move the file cursor to the desired archive byte, and then ...

Call a C++ function from a C source code

Hi, Is it possible to call a C++ function from a C source code? Please advice. Many thanks. ...

Initialsing Array of Structs in C

Hi, I'm looking to initialize a global array of stucts in C within the header file however it keeps complaining when compiling. Here's my struct typedef struct { char input[100][100]; int count; char name; }INPUT; extern INPUT[] global; Thanks ...

Lua shutdown/End of the program execution callback

I am writing a module for Lua. On closing the lua interpreter it must run clean up routines even if user forgets to call shutdown routine implicitly. The module is mostly written in C. What callback in Lua C Api should I use to detect end of program execution? The only idea I have come with is using __gc metamethod on table representi...

Writing a library with C and C++ interfaces, which way to wrap?

When preparing a library (let's call it libfoo), I find myself presented with the following dilemma: do I write it as a C++ library with a C wrapper: namespace Foo { class Bar { ... }; } /* Separate C header. #ifdef __cplusplus omitted for brevity. */ extern "C" { typedef void *FooBar; FooBar* foo_bar_new() { return new Foo...

Check if a number x is positive (x>0) by ONLY using bitwise operators in C.

isPositive - return 1 if x > 0, return 0 otherwise Example: isPositive(-1) = 0. Legal ops: ! ~ & ^ | + << >>(arithmetic shift) Max ops: 8 Note: No conditional statements are allowed. size of int is a word(4 bytes). It is a signed representation using two's compliment. int isPositive(int x) { return ???; } ...