Accessing 2D array values using a pointer

I need to take a 2d array (Grid) from stdin, do some manupulation to the chars and print a new grid with the changes. My strategy was to make a Struc with a Grid grid[LINES][COLUMNS] then use getChar() to push each char into grid using a pointer. I...
more »

2017-10-14 22:10 (1) Answers

C, counting the number of blankspaces

I'm writing a function that replaces blank spaces into '-' (<- this character). I ultimately want to return how many changes I made. #include <stdio.h> int replace(char c[]) { int i, cnt; cnt = 0; for (i = 0; c[i] != EOF; i++) ...
more »

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

Concurrency race between child and parent signals

I found this problem in a past exam from CMU and I can't get how the outputs were possible. basically, the idea behind it that there is a parent process that blocks a user-defined signal, then the parent forks a child. and based on which process tha...
more »

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

function pointers in a struct

I was trying to figure out function pointers. My code looks like this I have a file.h where I have a struct that hast 2 members typedef struct _node_ { char* string; int (*compare)(int a, int b); } node in that same file, I have a prototyp...
more »

2017-10-14 09:10 (1) Answers

Pass Lines of Code as an Argument in C

I'm working on a project in which I'm on a fairly strict word limit (I'm not 100% certain what qualifies as a word). I'm looking to pass lines of code into a function as an argument, I've seen this done in JavaScript but I cannot find anything on it...
more »

2017-10-12 14:10 (1) Answers

Input string without knowing the size

What's the way when i want to store string that i don't know the size. I do like this: #include <stdio.h> #include <conio.h> int main () { char * str; str = (char *)malloc(sizeof(char) + 1); str[1] = '\0'; int i = 0...
more »

2017-10-12 11:10 (4) Answers

Retrieving 2D array from pointer in C

I tried the following code char arr[5] = {'A', 'E', 'I', 'O', 'U'}; char (*p_arr)[1] = &arr; printf("%c\n", p_arr[0][4]); //returns 'U' On this stackoverflow thread, char (*p_arr2D)[m] = &arr2D //or arr2D is also a synt...
more »

2017-10-11 12:10 (4) Answers

Linked list implementation mistake in C

I have a program written in C. And I struggle with the effect I can't understand. The app reads a sequence of words as a command line input. While reading an input it puts one-by-one words into a list. And then it prints the list. What blows my mind ...
more »

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

Error reading characters of string after wcscpy_s

I have a problem with the wcscpy_s function. After wcscpy_s returns the parameter (stringOneand stringTwo) of my function are not readable. Here is simple demo to show the problem. void testFunc(LPCWSTR stringOne, LPCWSTR stringTwo) { wchar_t*...
more »

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

How to use a member function with std::bsearch

I have a C++ class but I'm also using some low level C and need to use the bsearch function. The last argument of bsearch is a comparison function, and I want to implement said function in a way that will allow it to access const private variables of...
more »

2017-10-10 09:10 (2) Answers

Working "within" a struct C/C++

I can think I can vaguely remember seeing a few years ago a way to essentially enter a variable Structure and work on its members without calling the variable name every time. similar to how you can us "using namespace bla". It may have even been fro...
more »

2017-10-10 08:10 (4) Answers