Most voted "c" questions
C is a general-purpose computer programming language used for operating systems, games, and other high-performance jobs and is clearly distinct from C++. It was developed in 1972 by Dennis Ritchie for use with the UNIX operating system.
Learn more…4,811 questions
Sort by count of
-
2
votes1
answer161
viewsProblem with malloc in C when creating string concatenation function
char *ft_concat_params(int argc, char **argv) { int index; int aux2; char **newString = argv; aux2 = 0; while (argv[aux2] != '\0') { index = ft_strlen(argv[aux2]); newString[aux2] = (char *) malloc…
-
2
votes2
answers136
viewsHow does -O3 optimization break some programs?
When compiling my own programs, I have the freedom to change some flags compiler and start using optimization -O3. This optimization manages to break some programs. I understand that the compiler…
-
2
votes1
answer64
viewsRetrieve arguments passed via ARGV in the terminal
I have a make file. Inside this make file, I call this file that has it: set -f; echo $1 | bc I want to recover function value in C for that Makefile file. Example: ./a.out "12 + 12" result: 24…
-
2
votes2
answers822
viewsHow to delete the last line of a text file in C language
Guys, I’m having a question about how I should delete the last line of a file using the C language. Could someone please help me. Below, follow my code. int quantidadeDeUsuarios = 0; Usuario…
-
2
votes1
answer1397
viewsHow do I correct "indefinite reference to 'function' in C?
Here is a simple example of TAD, which shows the error. file. h #include <stdio.h> #include <stdlib.h> int teste(); file. c #include "arquivo.h" int teste() { int a=5, b=10; return a+b;…
-
2
votes2
answers463
viewsStruct definition in C
Hello, my teacher has made the following definition of some structs for a list code in data structure, but unfortunately I cannot understand the definition of each struct itself. typedef struct{ int…
-
2
votes1
answer800
viewsstdafx. h library error
Does anyone know why there’s a mistake in this library and how to fix it? This is stated in the codeblocks header: #include "stdafx.h" #include <windows.h> #define TAM_PILHA 2 #define…
-
2
votes1
answer164
viewsBreak string with multiple symbols
I have a string in the following format: 0:name:password:email:etc I need to separate it into each ':', and I’m doing this with the Strtok(string function, ':'). The problem is that the password can…
casked 6 years, 11 months ago Gabriel Távora 55 -
2
votes1
answer132
views -
2
votes1
answer91
viewsHow to get a result type n1 + N2 + n... = x?
I am learning programming in C online and wrote this code to find the perfect numbers in a given range, but I would like to show the result with the sum of the divisors, for example : 1 + 2 + 3 = 6…
casked 7 years, 8 months ago Jose Marcio 21 -
2
votes2
answers2674
viewsHandler? What is this and what is it for in C/C++?
For a long time I’ve seen many code using this type HANDLER. What is it and what is it for? Where I find tutorials that teach you how to use it.
-
2
votes1
answer58
viewsIncrement and decrement do not work in expected order
int main(){ int i=5; printf("%d%d%d%d%d",i++,i--,++i,--i,i); } output: 45555 Why this exit? I did not understand correctly the reason for this exit.…
-
2
votes3
answers972
viewsHow to get the buffer from the socket?
I am receiving a lot of data coming from a server, the client(the code below), after sending a message, it receives another, but I would like to know the size of the message that is coming from the…
-
2
votes1
answer438
viewsHow to use Esc to stop a program in the middle of its C execution?
I would like to stop the programme by pressing ESC at any time, as would be possible?
-
2
votes3
answers649
viewsBinary tree removal
Personal as the tree looks after the removal of the number 40? In my understanding, instead of 40 would be number 41, right 44 and left 30. And the right of the 44 the number 49, to right?…
-
2
votes2
answers1067
views -
2
votes1
answer9018
viewsHow to leave code in language format within word
I currently have a code in the C language. I need to present this code in a PDF or .doc. But formatting a code in Microsoft Word to make it equal in the IDE is very laborious. Is there any tool that…
-
2
votes1
answer159
viewsIs this code O(n)?
#include <stdlib.h> #include <time.h> int maior(int n, int A[]){ if(n==1) return A[0]; if(maior(n-1, A)<A[n-1]) return A[n-1]; else return maior(n-1,A); } int main(){ int n, i;…
casked 6 years, 10 months ago Hatus Daniel 102 -
2
votes1
answer193
viewsHow to present only even and odd values with three variables in C?
My variables are : int codigo; --> Sendo esta variável para o switch int numero1,numero2,numero3; User will enter with three variables : printf("Digite o primeiro numero inteiro: "); scanf("%d",…
-
2
votes1
answer10388
viewsHow to present only negative values in C?
I have three variables : int numero1,numero2,numero3; After you have declared them, I am asked the user to fill them in : printf("Digite o primeiro numero inteiro: "); scanf("%d", &numero1);…
-
2
votes2
answers3541
viewsAlgorithm to calculate lifetime in days
He wanted to know how many days I have lived between the date I was born to this day, including leap years. This is how I’m doing, but I don’t know how to finish: #include<stdio.h>…
-
2
votes2
answers363
viewsif-Else command is not working
In one of the exercises of a book I’m reading, I’m asked to trace a person’s "profile" according to the year she was born (like those Facebook tests) but in order to limit the possibility of what is…
-
2
votes1
answer1217
viewsConversion from Farenheit to Centigrade always gives zero
This is the exercise: 1.12.3. Conversion from Farenheit degrees to centigrade is obtained by 5 C = 9(F - 32) Make an algorithm that calculates and writes a table of centigrade as a function of…
-
2
votes1
answer313
viewsLoop for reading text file reads the last line twice
I’m doing a test to read a simple txt file with three numbers: 1 2 3 #include <stdio.h> #include <stdlib.h> int main() { int conta; FILE* arq = fopen("dicionario.txt", "r");…
casked 6 years, 10 months ago Caio Teixeira 61 -
2
votes1
answer135
views -
2
votes1
answer181
viewsOrder Growth
Needed help to figure out the correct calculation of the order of growth of this code snippet (function of N=2 M) int sum=0; for (int i = 0; i < = N; i++) for(j = 1; j <= N; j++) for(k = 1; k…
-
2
votes1
answer27466
viewsHow to convert string to int type in c
I tried using itoa, but it seems that the Uri platform does not accept, someone could give me another way to convert from string to int Here’s the code I tried itoa(n1, p1, 10);…
casked 6 years, 10 months ago rafael marques 939 -
2
votes0
answers160
viewsttyS0 Serial Communication Error
I’m utilizing terminal serial TTL communication with an Orange Pi One and a PIC16F628A. The program that is on the microcontroller is simple: if it receives the character '1' puts a bit at a high…
-
2
votes1
answer242
viewsHow to access a pointer within a pointer structure
I know that to access a normal variable within a pointer structure I can use this syntax: struct teste { int valor; int *aponta; }; struct teste testando, *testado; testado = &testando; testado…
-
2
votes1
answer60
viewsUsing Linux libraries
I am developing a software in C that receives information and need to verify that it is correct through a CRC-16, searching found a lib only for CRC called libcrc.org but also found something on…
-
2
votes1
answer1101
viewsMaximum possible size to allocate a vector
Guys, I have a data structure project that’s meant to analyze search algorithms on the largest possible vector that my machine can allocate. Can someone help me figure out how to create a vector of…
-
2
votes3
answers378
views -
2
votes2
answers247
viewsTabulated problem in C
Can anyone tell me why the looping isn’t working properly? It was to print the 0 to 10 times, but instead it is printing typed number * 11. Follow the code: #include <stdio.h> int main(void) {…
casked 6 years, 8 months ago Thiago Henrique Domingues 167 -
2
votes1
answer887
viewsMatrix multiplication by matrix transposed in C language
I am new to programming and I am trying to make a program in C language that multiplies a 3x3 matrix by transposing it and prints the result. I’m having a hard time creating a multiplication…
-
2
votes1
answer129
viewsHow to reuse a function correctly in C?
I have the following functions : int divisibilidade3(int num); int divisibilidade9(int num); int testarDivisibilidade(int dividendo, int divisor); With the function testarDivisibilidade I’ll test…
-
2
votes4
answers191
viewsCan you make one simpler than that?
I don’t understand this decrease with the increment together. Read 2 integers I, F with I < F and check whether I is smaller than the F. Print I, F, successor to I, predecessor of F, successor of…
-
2
votes1
answer511
viewslvalue required as left operand of assignment - rest of division
I’m having a problem making rest of the division. Gave that mistake: value required as left operand of assignment How do I fix it? #include <stdio.h> #include <stdlib.h> int main() { int…
-
2
votes1
answer82
viewsHow to pass values via terminal to a program function
#include <stdio.h> #include <string.h> void soma(int a,int b); int main(int argc,char *argv[]) { printf("A soma="); return 0; } void soma(int a,int b){ printf("%d\n",a+b); } As step the…
-
2
votes2
answers303
viewsGiving "Segmentation fault" when I try to open C files
The following code gives me "Segmentation fault (core dumped)" when trying to open the file after declaration and filling a string with sprintf. //Sem as duas seguintes linhas, o código roda…
-
2
votes1
answer108
viewsC program to concatenate strings does not execute correctly
include int main(){ void concatenarStrings(char string1[], int t1, char string2[], int t2, char string3[]); char palavra1[]={'p','a','o','c','o','m'}; char…
-
2
votes1
answer2383
viewsHow to sort two vectors (ascending order ) into a third vector using only one loop?
My teacher posed this problem and I’m not able to sort in ascending order just by using a loop to sort. #include<stdio.h> main(){ int i,a[5]={1,4,8,9,11},b[5]={3,6,7,10,15},c[10];…
-
2
votes2
answers455
viewsCalculate memory address by pointer arithmetic
Suppose the elements of the vector v are of the type int and each int takes 8 bytes on your computer. If the address of v[0] is 55000, what is the value of the expression v + 3?…
-
2
votes2
answers65
viewsSegmentation Fault when removing list occurrences
The following code aims to remove all occurrences of an integer in a list, (linked lists), returning at the end, the number of elements removed. Give me the error of Segmentation fault. I appreciate…
-
2
votes3
answers1436
viewsWhat is the fastest way to calculate the sequence of Fibonacci
I’m asking a question that is Fibonacci de Novo! the tests give the expected result only that gives Time limit exceeded, wanted if you have a faster way to calculate My code #include <stdio.h>…
-
2
votes2
answers607
viewsIs it possible somehow to overload functions in C?
I’m already programming in C, in a procedural way, but a few months ago I started programming oriented to objects. In Java, it is possible to overload functions. Since Java is an object-oriented…
-
2
votes1
answer895
viewsMeasure memory usage in c
Hi, can I measure the use of ram memory of a program made in c? Do you have any specific tool or something like?
-
2
votes1
answer2486
viewsStack, pop function, it has to remove at the end
#include <stdio.h> #include <stdlib.h> typedef struct pilhaElement{ int data; struct pilhaElement *next; }PilhaElment; typedef struct pilha{ PilhaElment *head; PilhaElment *tail; int…
-
2
votes1
answer166
viewsWrong result when calculating BMI
I am doing an exercise with the C language to calculate the BMI, there is no error in the compiler but the result goes wrong, I have already looked at the code and I do not find the error at all.…
casked 7 years, 6 months ago Rebeca Aguirrer 177 -
2
votes1
answer59
viewsSearch between two vectors
I’m doing a project for a class, but I’m having some problems. The problem to overcome is, in a text file, composed of a id \t and a fixed 2048 sequence '0' and '1', insert a sequence and find the…
-
2
votes2
answers169
viewsPassing struct to function giving error
I am finalizing a phone book and the program compiles almost the entire, except in the function with the method of ordering the names. In the following code snippet, the compiler detects error the…
casked 7 years, 5 months ago Wilson Neto 21