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
-
6
votes2
answers148
viewsWhy doesn’t the pointer increase the value?
Here was to increase the value of the variable, but it does not work. #include <stdio.h> #include <stdlib.h> int main() { int *p, x = 10; p = &x; *p = (*p)++; printf("%d \n", *p);…
-
6
votes1
answer1263
viewsHow to avoid buffer overflow in C/C++
The program below allows the occurrence of memory overflow, as it is possible to overwrite the variable zero, placing a value "large" in the variable buffer. How to make a safe program by avoiding…
-
6
votes3
answers9114
viewsWhat are the differences between printf, fprintf, sprintf, snprintf, printf_s and fprintf_s?
Researching I noticed that there are several variations of printf, but I did not understand which differences and which to use in a certain circumstance. I would like to know the purpose of each…
-
6
votes1
answer282
viewsIs there any way to assign values to a vector faster?
For example, I have the statement of the following vector: float vet[3] = {1, 1, 1}; It would be possible to change all values of the same at once, without having to change one by one element or…
-
6
votes1
answer1726
viewsDifference between fflush and setbuf
What is the difference between the functions fflush(stdin); and **setbuf(stdin, NULL);**? When to use and when not to use each?
-
6
votes1
answer1153
viewsWhat’s the head of the chain list?
I didn’t understand what head or (head) of the list means, and what is the advantage in using it?
-
6
votes1
answer1353
viewsHow to return or extract more than one value from a function?
integerPower( int y ){ int base2; int base3; int base4; int total; base2 = pow( y , 2); base3 = pow( y, 3); base4 = pow( y, 4); When I call this function (I did not type return because that’s the…
-
6
votes2
answers1478
viewsHow to verify the existence of a folder?
To verify the existence of a folder with a C/C++ program, it looks for the directory, if it does not find the specified directory, it will make the decision to create it.
-
6
votes1
answer1950
viewsHow do I save a string of indefinite size to a structure?
#include <stdio.h> #include <stdlib.h> #include <string.h> struct Ecoponto{ int codigo; int contentores[3]; char cidade[20]; char *rua; int nporta; }; int main(int argc, char**…
-
6
votes1
answer75
views -
6
votes1
answer2747
viewsRaw Strength Algorithm for Sudoku Game Resolution in C
I have the following code written in C: #include <stdio.h> #include <stdlib.h> #include <time.h> // Variáveis globais int jogo_tabuleiro[9][9] = {0}; int func_quadrante(int…
-
6
votes4
answers14489
viewsInvert string in C
I’m trying to reverse a string in C but the function is clearing it: for(i = 0; i < (int)(size/2); i++) { tmp = buffer[i]; //armazena o character inicial buffer[i] = buffer[size - i]; //Troca o…
-
6
votes1
answer90
viewsHow is it correct to declare a variable that is a pointer?
I see some people do int* variavel; And some people do int *variavel; What is right?
-
6
votes1
answer4695
viewsHow to identify the type of variable in C?
In languages such as Nodejs, Ruby, Moon, etc. When I want to know what the type of my variable is just use the function typeof (not necessarily in the cited languages) that returns a String with the…
-
6
votes1
answer282
viewsShould we disregard the return of functions in C that already receive the desired value by the parameter by reference?
Looking at the documentation of scanf() I saw that it returns a value, but I see the codes using it without using that return. This is right?…
-
6
votes3
answers137
viewsAccess to pointer on main
Why in the statement as argument in function main(): char* argv[] instead of char argv[] i can access the information. I know one is pointer. I can’t access when it’s not pointer. #include…
-
6
votes1
answer214
viewsError while printing static list
How do I print my static list? #include <stdio.h> #include <stdlib.h> #define MAX 3 struct alunos { int matricula; char nome[30]; float nota1, nota2; }; typedef struct lista { int quant;…
-
6
votes1
answer163
viewsWhat is the "@" inside the Solve function printf for
#include <stdio.h> #include <stdlib.h> void solve(int QTD_DISCOS, int origem, int destino, int temp) { static int rank = 0; if (QTD_DISCOS > 0) { solve(QTD_DISCOS-1, origem, temp,…
casked 7 years, 5 months ago Amanda Silva 89 -
6
votes2
answers140
viewsIs Array a C pointer?
I am reading a book about C pointers, but as I am new to such a language, still for me the concept of pointers is a bit complex, and when reading the following definition, I came to the question…
-
6
votes2
answers146
viewsPointer changes address when exiting function
When performing a dynamic allocation of a vector or matrix in C, the pointer for that allocation changes address when leaving the function, before it was pointing to the initial address of the…
-
6
votes5
answers7439
viewsExercise with odd pairs in C
Statement - Make an algorithm that reads a set of numbers (X) and indicate the amount of even numbers (Qpares) and the amount of odd numbers (Qimpares) read. Note: Entering values ends when the user…
-
6
votes2
answers119
viewsWhat’s going on in my C program?
I just have to add the lines but the values don’t make sense: Here the code: #include <stdio.h> #include <stdlib.h> int main (){ int matriz[6][6],i,h,somalinha[6]; for(i=0;i<=4;i++){…
-
6
votes1
answer4920
viewsIs there a difference between using "Return" or "Exit()" to terminate the "main()" function?
The function exit() closes the execution of the application immediately. The command return makes you quit the function, but when you’re inside the main() will exit the application, including the…
-
6
votes2
answers4614
viewsCharacter size (ASCII vs other encodings) in bytes
Seeing this issue a doubt arose, coming from PHP and in the past having "problems" derived from character encoding, ex: srtpos vs mb_strpos, i knew that all ASCII characters have 1 byte, but I…
-
6
votes3
answers234
viewsGlobal variables recursion
I’m learning recursion and have doubts about using global variables, particularly I think a gambit inelegant, maybe I’m wrong. I made a code to add positive numbers and used a variable called sum. I…
-
6
votes1
answer138
viewsWhy is Offloading for the GPU a good idea?
I follow some forums on the Internet and I realize that recently there has been much talk of holding Offloading tasks for the GPU. Mozilla has implemented a new engine for its browser called Servo.…
-
6
votes3
answers342
viewsWhy doesn’t the while stop?
#include <stdlib.h> #include <stdio.h> int main() { int i,j; char elenco[30]; while(elenco[i]!='s' || i<=20) { printf("indique um menbro do elenco ,se quiser sair escreva apenas a…
-
6
votes1
answer5856
viewsDoubts in Arvore Binaria in C - Printing order, pre-order and post-order
I have several doubts about the operation of binary tree in C. I have a code for insertion, removal and printing in order, pre-order and post-order. These codes were taken from the Internet, because…
-
6
votes1
answer87
viewsSymbols in compilation time
When compiling only with -c and when displaying the symbols with $nm ficheiro.o, what the symbol means C and which section is assigned to it? I have read that it means that the symbol is common and…
-
6
votes1
answer7278
viewsHow to use the function toupper() in char in C?
I’m creating a variable: char nome[20]; After this, I am asking the user to enter a name: printf("Digite um nome : "); scanf("%20s",&nome); And I’m checking to see if the name is correct:…
-
6
votes1
answer2959
viewsWhat’s the difference between C and C99?
I saw C99 in text and I was curious there is some difference between normal C and C99?
-
6
votes1
answer41
viewsMy factorial function does not return the expected value! Language C
My teacher is starting to pass functions, and asked us to do a factorial function of a number, but it always returns the wrong value and I do not know what happens. Code: int fatorial(int n) { int…
-
6
votes4
answers4160
viewsCopy from txt file to other
int main(void) { void copiaConteudo(FILE *arquivo, FILE *arquivo1); FILE *arquivo = fopen("tmp/exercicio.txt","r"); if (arquivo == NULL) { printf ("Não foi possível abrir o arquivo"); return 1; }…
-
6
votes2
answers165
views -
6
votes1
answer132
viewsAre variables randomly allocated in memory?
In a book about C, in which I started studying variables, it said that variables were randomly put into memory, for example: int a; int b; printf("a = %d\n", &a); --> 5000 (endereço) (%d ao…
-
6
votes5
answers96
viewsMatrix with out-of-range index returning correct values
I was trying to create a matrix using while and realized that the program displays all the elements correctly if I just increment the value of j (column) up to 8. The program was not supposed to…
-
6
votes2
answers198
viewsstrcpy is merging numeric format with other chars
I don’t know if I made myself clear in the title, but when using strcpy() to copy a char* to another when I put a format like this "teste" it works normally, but when I put a string 3 letter format…
-
6
votes0
answers145
viewsAlgorithm by Christofides - TSP, Problem in transforming the AGM into a graph with all vertices with even degree
I am carrying out the implementation of the algorithm of Christofides and input I receive the data from TSPLIB. Christofides' Algorithm has the following steps: Find the minimum generating tree Find…
-
6
votes1
answer372
viewsExecution Time in Programming Solution Challenge
Hello, I need to ask the following question: https://olimpiada.ic.unicamp.br/pratique/p2/2017/f3/arranhaceu/ That is the statement: A residential skyscraper has N floors, numbered from 1 to N. The…
casked 6 years, 4 months ago Antony Leme 197 -
6
votes3
answers417
viewsCounter of a subsequence of repeated strings in C
Consider a string composed of several subsequences. for example: cccaaaabbbbxdddddddaaannn. The smallest subsequence is the letter x, with only one element; the largest subsequence is the letter d,…
-
6
votes1
answer79
viewsWhat is the difference between the function "malloc()" and a created variable?
I was reading some codes in C and I realized that to generate some specific object is used the function malloc(). It is not easier to create this object in a variable than to use the malloc()? Here…
-
5
votes4
answers556
viewsWhat is the fastest, most memory-saving type?
I am making a game of navinha in C, and therefore need to put in a vector a large amount of projectiles. These projectiles have at least one position and speed to make calculations, and I’m trying…
-
5
votes2
answers1093
viewsHow to compile a *.c file with Clang to signal problems?
In GCC I typed in the terminal: gcc -wall -o nomedoarquivo.c nomedoexecutavel or if you only had 1 file . c [OBS.: typed "a" to make it easier in the]: gcc -wall -o *.c a The restriction I used, if…
-
5
votes3
answers150
viewsCrash after reading value with scanf
First, I am "Noob" in programming. I started college today, and the subject was already rolling (third call has its consequences =P). The code is simple, the third I created, however, after…
-
5
votes1
answer57581
viewsHow to use mod in C C++?
how do I use the MOD function in C C++? (N MOD 2) = 0 I have to use this line of my code.
-
5
votes1
answer104
viewsARM-M4 Math Operations Lock When PWM Interrupt Is On
When I turn off the timer overflow interruption from PWM (+- 15Khz) operations occur normally. But when it is turned on the processor gets lost in floating point operations. I follow by the debug in…
-
5
votes3
answers238
viewsHow to stop three loopings for in C
Rstou trying to implement the AI ordered search algorithm and I have reached a point where I need to stop all loopings if I have found the NODE searched. Look what I did, but it doesn’t work. I know…
-
5
votes1
answer152
viewsCalculate the time a car was parked
I’m reading a file parque.txt which contains the time a car has been in a car park of the type "9h00 10h30", this in each line. I was trying to get those hours on every block of char, in this case…
casked 10 years, 5 months ago Miguel Freitas 53 -
5
votes1
answer394
viewsHow are the standard library functions of different programming languages implemented?
How are standard libraries of different programming languages implemented? For example, stdlib.h, or Java.Swing, how the function is implemented System.out.prinln() for example.…
-
5
votes1
answer905
viewsJava use library . DLL
I’m having trouble creating the java interface, because I can’t understand the header of the function in C. Example Header function C: CMOEP_API char * CALLCONV CMP_GetLastError( ); Now in java I…