I'm struggling with the following bit of code(/challenge) and I was wondering what would be the best way to solve it.
Pseudo(-like) code
If I understand the code correctly it does:
var val = 1
foreach (char in firstargument):
val = val * ((ascii)char + 27137)
if (val == 9215629587130840783880821452128359619700556749382698126651526...
I am coding for a rar password cracker. I am reading the password from a file and passing it to sprintf function. This is the code.
FILE* fp = fopen("password.txt","r");
while ( fgets ( pword, sizeof(pword), fp ) != NULL )
{
sprintf(command, "rar e -p%s realp.rar", pword);
printf(command);
//system...
#include<stdio.h>
int fun(int, int);
typedef int (*pf) (int, int);
int proc(pf, int, int);
int main()
{
printf("%d\n", proc(fun, 6, 6));
return 0;
}
int fun(int a, int b)
{
return (a==b);
}
int proc(pf p, int a, int b)
{
return ((*p)(a, b));
}
// direct link of program : http://codepad.org/fBIPiHGT
...
Given 2 functions Translate(x,y) and Scale(x), I want the camera's position to always be the center of the screen. There is also a scalefactor variable and by modifying it it either zooms in or out from the center of the screen. Given that I know the dimensions of the screen in pixels, how could I achieve this? Thanks
...
In my project I have a method that creates a string from integers (using strcat) and writes it into a file. Unfortunately it does have a memory leak. While tracking that leak down I simplified my code to the following. I can't seem to locate or even fix it. This is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int...
Hi,
I have two processes which are communicating over a pair of sockets created with socketpair() and SOCK_SEQPACKET. Like this:
int ipc_sockets[2];
socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, ipc_sockets);
As I understand it, I should see MSG_EOR in the msg_flags member of "struct msghdr" when receiving a SOCK_SEQPACKET record. I am set...
I just finished a homework problem for Computer Science 1 (yes, it's homework, but hear me out!). Now, the assignment is 100% complete and working, so I don't need help on it. My question involves the efficiency of an algorithm I'm using (we aren't graded on algorithmic efficiency yet, I'm just really curious).
The function I'm about to...
Why does break statement ends the nested loop?it should get the iteration of the inner loop to stop while the outer loop should continue doing its work.
int main()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
break;
}
}
}
This code breaks at the first iteration.
...
Possible Duplicates:
How would you set a variable to the largest number possible in C?
maximum value of int
I need to use the maximum integer value in my my code, but I don't want to explicitly write 4294967295. Is it defined somewhere?
...
plz. give the ans quickly.
...
I want to copy a float buffer into a char (byte) buffer without allocating memory for two separate buffers. In another words I want to use one buffer and copy in place.
The Problem is that if I need a float buffer then in order to copy that to a char then I will need a char* pointer; If I were copying from float* to float* it would be ...
Hi all, I should write a function to get some information about the system (the most important information is the the architecture). I found the function uname which can be used including sys/utsname.h. Well, though I googled and I read the documentation, I couldn't find any example of the function and I don't understand how to use uname...
How do you integrate C or C++ open-source third party libraries in your projects? Do you copy all the files it comes with (i.e. README, makefiles etc) to a separate directory somewhere inside the project and build it using its configs? Or do you only get needed source files and headers from a source package? Or do you just install pre-bu...
I want to write a function that unpacks a char* buffer to a float* buffer.
The char* buffer was originally packed as floats to bytes.
What is the best way to do this?
I have implemented integers below.
I have packed an array of 4 byte sized integers in a char* buffer.
This is the function I used to unpack it and assign it to int*.
voi...
Can someone remind me why this works?
A function requiring int* could take as input an (obviously)
int *integer;
but it could also accept
&var->integer
with var being var_t*, where var_t:
typedef struct {
int integer;
} var_t;
why is the 2nd accepted?
edit: oopsy, question is same but var is actually a var_t* (and not a v...
I had this working previously, but I didn't understand how, so I'm attempting to rewrite a bit of code.
Everything seems to be going fine, except when I try to use getaddrinfo(), I'm getting back a result of -7, which translates into the error "ai_socktype not supported".
I'm willing to bet it's simply me still getting a handle on poin...
Hello!
I'd like to detect from an application wether gdb is running. The standard way would be the following:
if (ptrace(PTRACE_TRACEME, 0, NULL, 0) == -1)
printf("traced!\n");
In this case ptrace returns an error if the current process is traced (i.e. running it with gdb or attaching to it).
But there is a serious problem with th...
Long:
char long_num[8];
for(i=0; i<8; i++)
long_num[i] = data[pos++];
memcpy(&res, long_num, 8);
The values in the long_num are as follows:
127 -1 -1 -1 -1 -1 -1 -1
res should be the maximum value of signed long, but is -129 instead.
EDIT: This one is taken care of. It was a result of communication problems: For the pers...
I'm writing an caching app that consumes large amounts of memory.
Hopefully, I'll manage my memory well enough, but I'm just thinking about what
to do if I do run out of memory.
If a call to allocate even a simple object fails, is it likely that even a syslog call
will also fail?
EDIT: Ok perhaps I should clarify the question. If ma...
I've recently been running one of my apps through Valgrind but there's a few MYSQL related leaks I can't fix. I put the offending code in the most basic form and tested that; I got the same leaks. Should I just disregard them or am I doing something wrong?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <mysql/mysql.h>
int main...