Questions tagged as 'c'

2
answers

Doubt about the "return" statement in recursion - C

I am studying the subject of recursion and I have two doubts that consist of the following: 1 .- I have seen that normally when calling a function within itself it is done through return , something like the following: return fibonacci(n...
asked by 07.04.2017 / 03:05
4
answers

Declare array inside loop vs empty it on each loop

I wonder if in C / C ++ it is better to declare a new array every loop loop: while(true) { char array[255] = ""; // Hacer algo con el array ... } Or empty it every turn of it: char array[255] = ""; while(true) { for(short i = 0; i...
asked by 09.04.2016 / 19:36
2
answers

fgets () returns NULL when reading text file

When I try to read my FILE fpTextFixed ( fgets(line,sizeof(line),fpTextFixed) ), it returned me NULL , but it was corroborating and my file was opened and written correctly. What I'm trying to do is write a binary file from re...
asked by 23.09.2016 / 03:00
2
answers

Using the macro __LINE__ - C

Greetings! I'm doing a C function that allows to obtain a more detailed record of what happens in the program, something similar to a debug , but trying to summarize things for the programmer. I found the Preprocessor documentation CPP...
asked by 25.01.2017 / 15:22
1
answer

Memory leak when assigning pointers

I've been doing some tests with this code: int main() { int i; float *a, *b; a=(float*)malloc(sizeof(float)*10); b=(float*)malloc(sizeof(float)*20); b = a; //FUGA DE MEMORIA??? free(a); free(b); } M...
asked by 30.05.2018 / 12:51
3
answers

I have problems with certain libraries C

I'm doing my university project and I'm creating several libraries, among them I have these #include "menus.h" #include "usuario.h" #include "listaMaterias.h" #include "validacion.h" The problem I have is that the library "validacion.h"...
asked by 28.11.2016 / 20:23
1
answer

How to use pragma pack?

I recently found this code #pragma pack(push) #pragma pack(2) I do not understand very well how to use this pre-processor directive although from what I see it is directly related to the structures     
asked by 02.05.2018 / 00:19
1
answer

pointer to nested struct

Code: #include <stdio.h> #include<stdlib.h> struct alumno1{ int edad1; float nota1; }; struct alumno{ int edad; float nota; struct alumno1 *alu1; }; int main(int argc,char **argv){ struct a...
asked by 05.04.2018 / 11:30
1
answer

Reserve memory in array of strings in c

Good afternoon, I want to create in c an array of strings, where each string has 1024 characters, for this I have a variable N where it tells me the number of strings I have, I'm trying it in the following way: char *frases[1024] = (char *) ma...
asked by 17.12.2017 / 17:12
2
answers

Where do the values of the following variables come from?

Could you explain how the variables x, y, z get this value in this code: #include <stdio.h> #include <stdlib.h> main(){ float x=1, *y, z=3; y= &x; x=z+5; y++; printf("%f\n",x); /*8.000000*/...
asked by 29.10.2018 / 17:51