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
-
4
votes1
answer592
viewsLarge switch case in C
I am developing a system for the college and I would like to know what is the best option, in the sense of optimization of the code, of improving even. I have a switch Menu case, where I have 88…
-
4
votes2
answers1491
viewsStore some elements of an array in another array
I have defined a array integer in which it will be pointed by a pointer and then I have another array which will store only a few numbers in which are even numbers, here is the code... void…
-
4
votes1
answer264
viewsPerformance difference between static and shared library
Which is the best performance? Compile the program using libraries such as Mysql Connector and Sqlite as Static (staying inside the compiled binary) or as Shared being separated from binary. In…
-
4
votes2
answers35
viewsStructures and selection of conditionals
Good afternoon! I’m doing a program that reads various cow data: among them age, production, etc. However, I am in doubt about how I can interrupt the event when typing code =0. As it is in the…
-
4
votes1
answer799
viewsUsing the lower triangularization method calculate the determinant of a transposed matrix
Using the lower triangularization method, I have to calculate the determinant of a transposed matrix. I want, from the transposed matrix, to calculate the determinant using the inferior…
-
4
votes1
answer84
viewsWhat good is C-EPERM?
What is the purpose of the -EPERM, after comparing the pointer p is null if(p == NULL) return -EPERM ; And I have to put these two libraries. #include <errno.h> #include <stddef.h>…
-
4
votes1
answer233
viewsSeeking Binaria and Ordination
There is some more efficient way to do that same function and do not know why on my computer is not working the code. #include <stdlib.h> #include <stdio.h> void ordena(int A[],int n);…
casked 9 years ago Matheus Francisco 650 -
4
votes1
answer149
viewsWrite list in binary file
The idea of this method is to write all the words of a list of nodes in a binary file. I have a linked list of nodes, where each node has two information, its information, and a reference to the…
-
4
votes1
answer1246
viewsPrint special characters in c that are in a.txt file with locale library. h
My college late semester program has several screens that print large texts from arquivo.txt, however, as I do in c language, some characters do not appear, such as ç, é, ã...And so on and so forth.…
-
4
votes1
answer302
viewsCommentary count // and /* */ in C
I’m trying to make a little program in C that opens a file .txt, .c or any other in read mode, to count the comments made with // or /* */. I’m doing it the following way: #include <stdio.h>…
-
4
votes2
answers1679
viewsHow do I generate random numbers and without repeating them in a time interval?
I am creating a 'game' in which it is necessary for the user to choose an interval, and in this interval, he chooses how many random numbers he wants to generate. However, in the random numbers…
-
4
votes2
answers1071
viewsGuess a number, and in attempts, by the percentage show hints
I am trying to create a game in which the user must determine an interval and guess a random number that is generated within this range. When the user inserts a number to guess, the program must…
-
4
votes1
answer1023
viewsWhy is the size of a struct not the sum of the sizes of its variables?
For example, the following code: #include <stdio.h> struct exemplo{ char letra; int numero; float flutuante; }; int main() { printf("Tamanho do char: %u\n", sizeof(char)); printf("Tamanho do…
-
4
votes1
answer442
viewsCopying string stored in pointer
What is wrong? #include <stdio.h> #include <string.h> int main(void) { char *str= " teste"; int j = 0; while(str[j] == ' ') j++; memcpy(str, &str[j], strlen(&str[j])+1);…
-
4
votes1
answer5292
viewsHow to make an HTTP GET request for a web service with Arduino
With a request via GET to a web service with Arduino, using the following URL and passing a parameter http://192.168. 0.1:8080/automation/Sensor? value=###, where ### is variable and is updated…
-
4
votes2
answers1128
viewsfree(): invalid next size (fast) while trying to free up memory
I have this struct in a data structure and need to free up memory with it used: typedef struct { int capacityOfElements; //capacidade do vetor int numberOfElements; //número de elementos presentes…
-
4
votes1
answer1523
viewsCorrect use of free() in function?
How to use function free() when it is used within a function, in that function Gero a dynamic vector and the function itself will be the return, example: int* copia(int *vet, int tam) { int i,…
-
4
votes1
answer124
views -
4
votes2
answers6127
viewsCode for calculating the first N primes in C?
First, I got this: #include <stdio.h> #include <stdlib.h> int main(){ int i=13,w=0,k; for(k=i-1;k!=1;k--){ if(i%k==0){w=1; break;} } if(w==0){ printf("\n%d eh primo",i); }…
-
4
votes2
answers549
viewsError while reading C file
But before making this code I created a text file called numero.txt and included it in the file: 23;45;89;-230 452;0;97;1 87;2;4;6 346;97;-5;3 Follow code with error, but I can’t find the error.…
-
4
votes1
answer1222
viewsScanf is not stopping on repeat
I have a loop while which will only end when 0 (zero) is entered. I have a variable which will receive a command option. Inside the loop I own a switch marry where: 0) exits the program (returns to…
-
4
votes1
answer1765
viewsC menu that moves with the arrow keys on the keyboard?
I saw once an algorithm in C where the menu selection had a "mini navigation" if I can call it that, where I used the arrow keys to navigate the menu and enter to select the option, I was curious to…
-
4
votes2
answers3911
viewsWhat is the difference between data types Enum, struct and Union in C?
I am reading the GNU’s C manual and I’m in the data types section and I notice a certain similarity between the types enum, struct, and union. Is the syntax the same, or is there something that…
-
4
votes2
answers503
viewsHow to hide a string in C, so that it is not readable in compiled code?
I have a string Hello World, but I don’t want to keep it as Hello World in C, I would like to keep it as some value in Base64, aes or binary, or similar, so that it is not readable in the code. How…
-
4
votes1
answer1504
viewserror: initializer element is not Constant
I’m trying to declare this buffer overall and when compiling it presents the following error error: initializer element is not Constant char *ls_buffer_PPouAUT = malloc(5120*sizeof(char)); How can I…
-
4
votes2
answers69
viewsHow should these variables end correctly without having a chance of memory Leak?
What is the right way to use the free() in that case, where ls_options will contain several ls_buffer_send? char **ls_options = (char**) malloc (200*sizeof(char)); char *ls_buffer_send = (char*)…
-
4
votes2
answers117
viewsHow do I use free() and return the same content?
I wanted to use the free() in ls_retorna in the following function, how could you do it with the best way? char* MemCpyX(char *as_origem, int an_inicio, int an_quantidade) { char *ls_retorno =…
-
4
votes3
answers408
viewsUse free() without malloc()?
May cause some problem in using the free() on a pointer that was not allocated with malloc() beyond the necessity itself? void funcao (int par) { char *palavra; if(par%2 == 0) { palavra =…
-
4
votes3
answers17331
viewsConvert Fractional decimal to binary
I’m trying to convert a fractional decimal number to binary. Let’s go to the example, representing, in binary, the number 0.625. 0,625 x 2 = 1,25 , so the first fraction is 1. It remains to…
casked 8 years, 8 months ago Matheus Francisco 650 -
4
votes1
answer66
viewsWhy doesn’t my Return return the i do for?
#include <stdio.h> #include <stdlib.h> int BuscaLinear(int *sequencia[], int tamanho, int valor) { int i; for(i=0;i<tamanho;i++) { if(sequencia[i] == valor) { return i; } } return -1;…
-
4
votes2
answers182
viewsExit multiple loops without using goto
Oops! The title says it all! Someone knows an interesting way to get out of more than one loop without using goto?
-
4
votes4
answers715
viewsWhat’s wrong with the c-code?
The task: Pedrinho and Zezinho need to study solving mathematical expressions for a test they will do. For this, they want to solve many exercises before the test. As they know how to program, so…
-
4
votes1
answer1369
viewsInsertion Sort in double-linked circular list
I’m having problems with Insertion Sort, it’s probably in the stopping condition, the problem I’m already days with this problem and so far I haven’t been able to leave the place. Could someone give…
-
4
votes1
answer96
viewsWhy not give Segmentation fault when writing to a "char *" without allocating memory?
My question is whether the compiler automatically allocates memory to the variable s1 char *s1; char s2[20]; //s1=(char*)malloc (sizeof(char)*20); s1="palavra1"; strcpy (s2,"palavra2");…
-
4
votes3
answers3650
viewsScanf function with variable amount of parameters, how to implement?
I have a text file (txt) that contains the following values: 12 90 These two values I keep and my variables a and b, that is to say a is equal 12 and b is equal 90, and I’m using the function…
-
4
votes1
answer7212
viewsPass Array as a function parameter
Make a program in C that reads a value x, dynamically create a vector of x elements and pass this vector to a function that will read the elements of this vector. Then, in the main program, the…
-
4
votes1
answer51
viewsUnsigned modifier for integer type in C
The works say that this modifier causes the variable not to accept negative values, but when I compile this code: #include <stdio.h> void main() { unsigned int idade; idade = -3; /* Não existe…
-
4
votes1
answer122
viewsRead elements from a file
Hi, I have a big problem! I have to read two very large numbers of a file and save each position in a list. I’m using fgetc to pick up each element, the two numbers are separated by a blank space,…
-
4
votes1
answer105
viewsVector reading in C is wrong
struct cadastro{ int codigo; char nome[200]; char cpf[11]; char rg[10]; char tel[12]; char end[100]; }cadastro;//struct do tipo cadastro. struct cadastro cd[max];//vetor da funcao cadastro de…
-
4
votes1
answer2845
viewsWhat is the correct way to declare a struct in C?
Also how to rename data types with structures? I have doubt about it because of a Windows Manager that I use has the following code: typedef struct exem exem; struct exem { tiposdedado variavel; };…
-
4
votes2
answers1267
viewsVariable declaration before the main() function and after the main() function in C
What is the difference between declaring any variable (in this case number) before function main()? int number = 0; int main() { printf(" The number is %d\n", number); return (0); } and after it.…
-
4
votes3
answers216
viewsWhy is there an asterisk left?
I want the number of rows and columns to be equal to input data. Why is this last *? Code: #include<stdio.h> #include<math.h> int row = 0; char column = 0; int n; int main ( void ) {…
-
4
votes3
answers315
viewsHow to access a pointer within a structure?
I need to know how to access the first position of the pointer vector *c_parte_real, as shown below: typedef struct{ struct char_vector{ char *c_parte_real[2], *c_parte_imag[2]; }c_vector; struct…
-
4
votes2
answers336
viewsWidth Search - error: 'str_no' undeclared (first use in this Function)
I have the following code on C, for a wide search: #include <stdio.h> #include <stdlib.h> #include <conio.h> //Variáveis globais int id = 0; int proximo = 0; //Função de Busca em…
-
4
votes2
answers756
viewsProblems with calculating "TREE OF LIFE"
Good afternoon, I have a problem I need to do the following: Create a program, in C language, that calculates the size of the tree of life, after a certain number of growth cycles, taking into…
-
4
votes1
answer1052
viewsParameters of the scanf function
When studying the function scanf with a little more depth I arose a doubt about the arguments I put before the % when reading a string, ie scanf("argumentos...%s",minhastring), in the following…
-
4
votes1
answer1072
viewsChar comparison, ignoring the case sensitive
The proposal is to create a program that compares n first positions of the two vectors and returns saying whether or not they are equal. So far so good, but I do not know how to ignore the case…
-
4
votes1
answer124
viewsHelp in struct C, unable to feed
Guys, good morning, I’m creating this simple code, just to read, and display, this vector information, like struct. Only that in executing this code, in the act of execution, I can not feed neither…
-
4
votes1
answer733
viewsLexical Analyzer using LEX
I am using the LEX generator to do a lexical analysis of a simple C++ code. The following code is from the generator: %{ #include<stdio.h> %} extern FILE *yyin; %% "<" {printf("(Identifier,…
-
4
votes1
answer97
viewsDoes it pay to store the value of a struct member in a local variable?
I see several programmers doing this. Instead of accessing a member of a struct directly, it copies the value to a local variable to the function and uses this variable. Is there performance gain in…