Using pointer arithmetic, it's possible to assign characters from one array to another. My question is, how does one do it given arbitrary start and stop points?
int main(void)
{
char string1[] = "something"; //[s][o][m][e][t][h][i][n][g][\0]
int start = 2, count = 3;
char string2[10] = {0};
char *ptr1 = &string1[start];...
I already know that I can trace memory leaks in my code with mtrace and valgrind on Linux, both of which are unavailable for Windows. Which Windows program would you recommend to trace memory leaks?
I'm an Eclipse user and I've been working with C for a month or two now, so I prefer a user-friendly solution over something more advanced....
what is the most advanced c or c++ book you ever read?
i am asking this because i already read lots and lots of books on c and c++ on a lot of topics including (object oriented programming-data structures and algorithms-network programming-parallel programming (MPI-PThreads-OpenMP-Cilk-Cuda)-boost library....). So whats next. I still wan...
Is there any way to decompile Linux .so?
...
Hi,
I have embedded HTML Tidy in my application to clean incoming HTML. But Tidy has a huge amount of bugs and fixing them directly in the source is my worst nightmare. Tidy source code is an unreadable abomination. Thousand+ line functions, poor variable naming, spaghetti code etc. It's truly horrible.
Worse yet, official development ...
I am trying to copy a file from a specified library to the current directory. I can copy text files perfectly. Any other files become corrupt. The program detects a feof before it should.
#include <stdio.h>
int BUFFER_SIZE = 1024;
FILE *source;
FILE *destination;
int n;
int count = 0;
int written = 0;
int main() {
unsigned char b...
I'm experiencing some problems with my C program on Linux. It compiles and runs just fine on Windows. The Linux terminal returns this information:
*** stack smashing detected ***: ./student terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x4b)[0xb7e908ab]
/lib/lib...
I've been trying to solve this bsearch homework problem for awhile now. I try using my code to first search for one entry like so:
int Compare(const void *a, const void *b);
void SortStudents(char *studentList[], size_t studentCount)
{
qsort(studentList, studentCount, sizeof(studentList[0]), Compare);
}
int Compare(const void *a...
bind() needs a length of the sockaddr structure you've given it.
Now, for unix sockets, sockaddr_un is used
What's the proper ways of calculating the length of this when you've filled in the sun_path member ? I've seen multiple approaches:
socklen_t len = sizeof(sockaddr_un);
socklen_t len = offsetof(sockaddr_un,sun_path) + strlen(addr...
Hello,
I have a small function that tries to print the fragment offset of an IP header.
ParseIpHeader(unsigned char *packet, int len)
{
struct ethhdr *ethernet_header;
struct iphdr *ip_header;
/* First Check if the packet contains an IP header using
the Ethernet header */
ethern...
I get a segmentation fault after freeing a certain pointer:
free(studentDB->name);
I can get its value without any errors or warnings:
printf("[DBG] studentDB->name: %s\n", studentDB->name);
However, as I said, the program crashes when I try to free it. What are the most common causes for a free command leading to a segmentation fa...
Hi,
This is the reader-writer problem for just read consistency.
Here is the algorithm,
void reader() {
while (1){
P(mutex);
rc++;
if (rc == 1) P(db); /* <---- A */
V(mutex); /* <---- B */
read_data_base();
P(mutex):
rc--;
V(mutex);
if (rc ==0) V(db);
}
...
Here's a simple example:
#include <stdlib.h>
int main(void) {
_set_error_mode(_OUT_TO_STDERR);
return EXIT_SUCCESS;
}
When compiling this program, I get the following problems:
main.c: In function 'main':
main.c:4: error: implicit declaration of function '_set_error_mode'
main.c:4: error: '_OUT_TO_STDERR' undeclared (first u...
Say I have a text file that has multiple names and their corresponding birthdays such as:
john doe 2 34
lauren doe 3 4
albert r. grifton 03 12
The converter program will make usernames for the students such as:
jd0234
ld0304
arg0312
The problem I am experiencing is adding the zeros for the if/else conditions for the odd amounts o...
Hi I'm writing rpn calculator in C and I'd to compile rpn expression to byte-code.
But I'm not sure what would be the data structure to represent them???
My stack data structure so far is
struct stack_t{
int type;
union {
double val;
char *str;
/* probably some more */
...
In the execve() man page it is said that argv is a list of string arguments which is ended by a null pointer. But what is the NP for? I mean, the number of arguments is stored in argc, so what's the point of the null pointer?
...
In C, shall I prefer constants over defines? I've reading a lot of code lately, and all of the examples make heavy use of defines.
...
Is it possible to write a C macro that returns the length of its arguments?
I want something that does:
foo(1) -> 1
foo(cat, dog) -> 2
foo(red, green, blue) -> 3
Even better if this macro can be defined in such a way that it works with ## so that
foo(1) -> bar1(1)
foo(cat, dog) -> bar2(cat, dog)
foo(red, green, blue) -> car3(red, gr...
For instance:
#include <stdio.h>
void why_cant_we_switch_him(void *ptr)
{
switch (ptr) {
case NULL:
printf("NULL!\n");
break;
default:
printf("%p!\n", ptr);
break;
}
}
int main(void)
{
void *foo = "toast";
why_cant_we_switch_him(foo);
return 0;
}
gcc ...
Please read before answering. I dont want you to state the obvious for me. THANKS :D
I am trying to differentiate between pointers and passing by value. And I think I understand them but one thing the source I was reading wasnt clear on is what is the difference between passing a pointer and passing by value. consider the following...
...