How do I set the private key for encrypting messages when using ECDSA in OpenSSL programmatically? I have the following code:
static int create_signature(unsigned char* hash)
{
EC_KEY *eckey=NULL;
EC_GROUP *ecgroup=NULL;
EVP_PKEY *evpkey=NULL;
unsigned char *signature=NULL;
point_conversion_form_t form = POINT_CONVERSION_UNCOM...
Possible Duplicate:
Static variable
How to access a static variable from another file in C?
As a Static variable has a file scope, I think there is no way we can access it outside a file. But still I feel there might be some trick or way to do the same.
...
Could someone provide an example of (reasonably) using the function shmat() with non-null second parameter?
The manual says:
#include <sys/shm.h>
void *shmat(int shmid, const void *shmaddr, int shmflg);
The shmat() function attaches the shared memory segment associated with the shared memory identifier shmid to the data se...
What is the fastest way to find if a number is even or odd?
...
This is shown when I try to debug my code with Eclipse:
I then tried creating a simple Hello World program manually with Notepad++ and the command-line gcc. When I launched the gdb debugger this happened:
(gdb) run
Starting program:
C:\Documents and
Settings\Pieter\Bureaublad/test.exe
Error creating process C:\Documents...
It's not possible to do something like fputs(4, fptOut); because fputs doesn't like integers. How can I work around this?
Doing fputs("4", fptOut); is not an option because I'm working with a counter value.
...
If C does not support passing a variable by reference, why does this work?
#include <stdio.h>
void f(int *j) {
(*j)++;
}
int main() {
int i = 20;
int *p = &i;
f(p);
printf("i = %d\n", i);
return 0;
}
Output
$ gcc -std=c99 test.c
$ a.exe
i = 21
...
i'm looking for a software which converts a c source code program to a xml-based ast representation? some sort of markup language.
example:
[function name="set_foo"]
[parameters]
[parameter name="bar" type="string" /]
[/parameters]
[return>
...
Develop a C program for file-copy where two processes work together to complete the task:
Parent process receives source filename and destination filename from command line. It opens the source file in read mode.
Use shared lock on the source file in both the processes. Use exclusive lock on the destination file. Do read/write operatio...
Background
I am designing an application which will convert text from one language to other. For example, input text hello will be converted to specified language text. This is done by having a lookup table for each language. Conversion algorithm has the following steps.
Looks for exact match. The whole word hello will be the pattern....
Why the code below does not work? I mean, it shows all kinds of weird characters on console output.
#include <stdio.h>
char mybuffer[80];
int main()
{
FILE * pFile;
pFile = fopen ("example.txt","r+");
if (pFile == NULL) perror ("Error opening file");
else {
fputs ("test",pFile);
fgets (mybuffer,80,pFil...
Hi all,
I was asked this question in some interview.
I was required to write code for finding junction in a linked list (which is in form of Y with both arms not necessarily equal) for production environment in O(1) space and linear time.
I came up with this solution (which i had previously seen somewhere) :
1. Measure lengths of both l...
Having looked at several available http server libraries I have not yet found what I am looking for and am sure I can't be the first to have this set of requirements.
I need a library which presents an API which is 'pipelined'. Pipelining is used to describe an HTTP feature where multiple HTTP requests can be sent across a TCP link at a...
Simple question: Can scanf read/accept a "small integer" into an unsigned char in ANSI C?
example code un_char.c:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
unsigned char character;
scanf("%hhu", &character);
return EXIT_SUCCESS;
}
Compiled as:
$ gcc -Wall -ansi -pedantic -o un_char un_char.c
un_char.c:...
So what I'm trying to do is write Japanese characters to my terminal
screen using C and wide characters.
The question is whats wrong with what I'm doing so that I can fix it,
what other caveats should I expect while using wide characters and
do you have any other comments about what I'm trying to do?
The bad code:
#include <stdio....
I am having an intermittent error causing my Python module to crash, and I'm assuming it's because of a memory error occurring by not getting the refcounts correct in the c code. I have a bit of code that gets a response at a random time from a remote location. Based on the data received, it needs to update a data variable which I should...
I often use convenience functions that return pointers to static buffers like this:
char* p(int x) {
static char res[512];
snprintf(res, sizeof(res)-1, "number is %d", x));
return res;
}
and use them all over the place as arguments to other functions:
...
some_func( somearg, p(6) );
....
However, this "convenience" ha...
Looking at this question that has just been asked: http://stackoverflow.com/questions/2231317/inconveniences-of-pointers-to-static-variables would doing something like this be considered bad practice, then?
char* strpart(char* string, int start, int count)
{
char* strtemp;
int i = 0; int j = 0;
int strL = strlen(string);
...
I am making a little calculator in C, and i want to pass simple arithmetic formulae to my program. But it really does not like me passing character '*' to my program.
Why not?
And how can I work around this without changing the asterix to something else?
Thanks
...
I'm moving from Java to C++ and have really enjoyed it. One thing I don't enjoy is not understanding memory at all because Java used to do that for me.
I've purchased a book : Memory as a Programming Concept in C and C++ - Frantisek Franek
Are there some good sites for me to go and learn interactively about C/C++ and memory use (tuto...