Not able to write in /dev/mem

The issue that I am experimenting is not related with open() or mmap() function, which are executed properly. I have disabled CONFIG_STRICT_DEVMEM in the kernel so I can read from /dev/mem without problems. Actually, I can do the following: const ch...
more »

2017-10-04 17:10 (0) Answers

Safe conversion from __int64 to size_t

I am working on Windows OS with Visual Studio 2017, and I obtained the following function to determine the size of a file from one of SO's answers: __int64 FileSize(const char *filename) { HANDLE hFile = CreateFile(filename, GENERIC_READ, ...
more »

2017-10-04 14:10 (4) Answers

Swap digits in a double in C

What I want to do in C is swap two digits in a double. For example, if the input is 54321.987 and I want to swap the 2nd with the 4th digit, the output should be 52341.987. Example when too small: 12.34 would output 1002.34. ...
more »

2017-10-04 14:10 (8) Answers

How to remove two commas of a csv file using c

My csv file looks something like this: Alice,Girl,19,Beauty Alec,,30,cool Now as shown in the above sample there are two commas in the second entry. Right now I am using the following instruction in c to read the csv and store it in the da...
more »

2017-10-03 21:10 (1) Answers

Weird behavior of a function

In an exercise, I need to compare an array of distances and tell the shortest paths. For this, I need to read an input file with the cities' coordinates (x,y) and find all the possible routes and calculate the total distance of each route. This first...
more »

2017-10-03 17:10 (0) Answers

Eclipse - Build vs Rebuild (makefile C project)

I have a makefile C project on Eclipse. When looking in the menu under Project > Build Targets there are a few options. These two interest me: Build... Rebuild Last Target The basic question is what does Eclipse to differently in both cases? To ...
more »

2017-10-03 11:10 (2) Answers

Are __func__ and __FUNCTION__ pointers persistent?

For gcc projects, are the pointers returned by __FUNCTION__, __FILE__ and __func__ guaranteed to point to persistent memory? (That is, can I safely deference the pointers in the scope of another function?) I know that __func__ is supposed to act l...
more »

2017-10-02 21:10 (3) Answers

Unit Testing C With Functions Not in Header

I'm starting to get into unit testing and I'm having trouble understanding something. My struggle boils down to how I would go about testing functions that are only in the .c source, and not declared in the .h header. There's certain functions that s...
more »

2017-10-02 20:10 (2) Answers

Finding pairs in an array

So what I am trying to do is make a code to find pair of numbers in an array. This code below works perfectly when there is a single pair of numbers. #include<stdio.h> main() { int arr[10], i, j, pairs = 0; int n; scanf("%d", &...
more »

2017-10-02 16:10 (2) Answers

call_usermodehelper doesn't work properly

I work on a kernel module for write something in a file with python from kernel space. First Try: I write this code for run python file from kernel: int ret = -1; char path[] = "/bin/bash"; char *argv[] = {path, "-c", "python", "/home/samba/gett...
more »

2017-10-02 13:10 (1) Answers

valgrind, total heap usage keeps increasing

Please take as an example below. It seems there is no memory leak but why total heap usage and bytes allocated keeps increasing? If I remove first part(test1), valgrind result does not show any increasing heap and always total heap usage: 1 allocs, 1...
more »

2017-10-02 10:10 (1) Answers

Applying alignas() to an entire struct in C

I expected it to be possible to apply alignas/_Alignas to an entire struct declaration, like this: #include <stddef.h> #include <stdalign.h> struct alignas(max_align_t) S { int field; }; struct S s = { 0 }; but both gcc and clang r...
more »

2017-10-02 03:10 (2) Answers

C Language: Why int variable can store char?

I am recently reading The C Programming Language by Kernighan. There is an example which defined a variable as int type but using getchar() to store in it. int x; x = getchar(); Why we can store a char data as a int variable? The only thing that ...
more »

2017-10-02 01:10 (5) Answers

C language - pointer arithmetic

The functions should use pointer arithmetic (instead of array subscripting). In other words, eliminate the loop index variables and all use of the [] operator in the functions. void set_complement(int *a, int n, int *complement) { //poin...
more »

2017-10-02 00:10 (3) Answers

3-way Merge Sort C program

I have trying to "upgrade" my normal merge sort for a school project. But my new code seems to not coorporate as it should so i have a MergeSort3way function that splits the Array inputed in 3 subArrays then it call itself till the sort is finished ...
more »

2017-10-01 17:10 (2) Answers

Adding 2 matrices using pointers

I can acheive it by passing (c,a,b) to add_mat function, where result of a,b is stored in c like, void add_mat(int c[][3], int a[][3], int b[][3], int m, int n) What should be the return type of add_mat if I want to construct the funtion in this w...
more »

2017-10-01 15:10 (3) Answers

How to implement gotoxy() using printf()

Can someone please tell me how gotoxy() is implemented using printf() void gotoxy(int x,int y) { printf("%c[%d;%df",0x1B,y,x); } What are the things written inside printf() supposed to mean to the compiler ? ...
more »

2017-09-30 15:09 (1) Answers