Output process - save data in file

Briefly, I'm testing this code in python: My idea is to save solut = one + two in a file after inputting the values by keyboard, but now I have a problem. NO message error and nothing is written in file. python 2.7 I have changed and saved the cod...
more »

2017-06-20 05:06 (2) Answers

C "for" loop iterating only once

For context, I'm trying to write code that solve this problem in C. The problem is relatively simple. The first input is an integer that represent the number of scores in a stream of scores. The following inputs are all integers that represent scor...
more »

2017-06-17 21:06 (1) Answers

Size of pointers and dynamic arrays

I'm relatively new to C, and I've been messing around with pointers to an int array to help solidify my understanding. Here is some code I typed up that confused me: #include <stdio.h> int main(int argc, char **argv) { int sizeOfInt = si...
more »

2017-06-17 18:06 (3) Answers

Why is this pointer variable assignment allowed?

While debugging a program of mine, I stumbled upon a weird behaviour of the gcc compiler. I don't know what's the correct title to describe this, but take a look at the code below. Basically, I had a function which received a void* arg as an argumen...
more »

2017-06-17 12:06 (1) Answers

Initialize C struct through a function

So I do have to write a vector-like data structure in C. Generally I made a structure like this: struct Vector { int length; int *elements; }; And functions like these: void initialize_vector(struct Vector* vector); void create_vector(str...
more »

2017-06-15 20:06 (2) Answers

Compare between pointers and integer

I have a question, I tried to copy one line from a pointer to file but there is one error that says that I cannot compare a interger with a pointer, can anyone help me? The error is in line ch = getc(file1); and while(ch != EOF) #include <stdio.h...
more »

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

Why can't I print the value at this pointer?

Following yesterday's question, I experimented some more with pointers. Specifically pointers of type int (*) [n] Here's some code I wrote : #include <stdio.h> int main(void) { int a[5] = {1, 2, 3, 4, 5}; int (*p) [5] = &a; ...
more »

2017-06-14 09:06 (3) Answers

Determine the size of buffer allocated in heap

I want to know the size of a buffer allocated using calloc in byte. By testing the following in my machine: double *buf = (double *) calloc(5, sizeof(double)); printf("%zu \n", sizeof(buf)); The result was 8 even when I change to only one element ...
more »

2017-06-12 08:06 (2) Answers

find and return a pointer to a object in a vector

New to c++, not really sure where I'm going wrong. Still wrapping my head around ptrs. I have a vector of profile objects. I want to find a particular object based on one of it's properties. Then I want to return that object. I don't want to make co...
more »

2017-06-05 05:06 (1) Answers

A program interpretation in C

I am new to c and sometimes I get confused by things I see. I have the following code: int sstmm_() {time_t ourtime; time(&ourtime); return (int)(ourtime&0x00000fff); } I do not understand what the meaning of ourtime&0x00000fff is? ...
more »

2017-06-04 15:06 (3) Answers

array of pointers and pointer to an array in c++

i have a class in which it's protected section i need to declare an array with unknown size (the size is given to the constructor as a parameter), so i looked around and found out that the best possible solution is to declare an array of pointers, ea...
more »

2017-06-03 16:06 (3) Answers

Why can't I use pointer addition instead of malloc

I was wondering why I have to use malloc to dynamically create memories, while I already have pointer addition to freely manipulate the memories. So I created this code, but this code corrupts, saying that 'stack around the variable 'a' was corrupted...
more »

2017-06-03 04:06 (4) Answers

What does allocating memory of size char * do?

char *str; str = malloc(sizeof(char) * 5); This code allocates 5 consecutive slots of memory to the variable str, which is of type char *. char *str; str = malloc(sizeof(char *) * 5); This is supposed to allocate 5 times the memory of an a...
more »

2017-05-25 15:05 (5) Answers

Order of evaluation of the given expressions

Expression 1: *p++; where p is a pointer to integer. p will be incremented first and then the value to which it is pointing to is taken due to associativity(right to left). Is it right? Expression 2: a=*p++; where p is a pointer to integer. Value ...
more »

2017-05-25 11:05 (6) Answers

Why doesn't GCC throw a warning in this example

With -Wsequence-point enabled, GCC should warn user when unexpected behaviour code is spotted. For example b = a + ++a; should be noticed by GCC and should be reported as "unexpected behaviour" code (because ISO C doesn't specify the order of eval...
more »

2017-05-14 13:05 (1) Answers