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
answer7425
viewsFunction takes as parameter a string array
I just started learning the C programming language and I’m having a hard time. I declare a string vector, pass values to that vector and then pass that same vector as a function argument. The…
-
2
votes1
answer395
viewsMerge a stack with a list
struct noPilha{ float peso; int idMala; char cor[20]; struct pessoa donoMala; struct noPilha* prox; }; typedef struct noPilha Elem; struct noLista{ struct noPilha mala; struct noLista *ant; struct…
casked 6 years, 11 months ago Márcio1994 29 -
2
votes1
answer108
viewsVariable char error C Visual Studio
I’m having problems using scanf_s in a char variable only in the visual studio. When it reaches the scanf_s line the program stops and brings me the following error: Exception thrown at 0x7893E63C…
-
2
votes1
answer79
viewsError in sorting numbers
Even numbers I managed to sort, only odd numbers I can’t sort. The memory address of the number appears. Link to the question: Even and Odd Here is my code: #include <stdio.h> int main(int…
-
2
votes1
answer59
viewsParentheses in a pointer to pointer
I’m studying a binary tree structure and I got in doubt in a part of the code. #include <stdio.h> #include <stdlib.h> typedef struct tree { int num; struct tree* sad; struct tree* sae; }…
-
2
votes1
answer132
viewsConcatenate variables into C
It is possible to concatenate 2 variables of different types and obtain a single variable that occupies the same bytes as the sum of the bytes of the 2 variables of different types? For example:…
casked 4 years, 7 months ago Ruben Pinto 23 -
2
votes1
answer122
viewsHow to copy a structure pointer?
Is it possible to clone a structure pointer? Follow the code: typedef struct{ int numero; }estrutura; int main(int argc, char *argv[]){ estrutura *i = (estrutura *)malloc(sizeof(estrutura));…
-
2
votes1
answer279
views -
2
votes2
answers108
viewsQuestion about array size
I have a question regarding the array, for example, if I have 2 arrays of size 9 and print the values of both it is normal for input 9 to get the value 0 of the next array ? This is more of a test,…
-
2
votes1
answer53
viewsWhy do different types of variables give different results when modified in a function?
I can’t understand why x and v[0] are different. void edit1 (int x) { x = 9 * x; } void edit2 (int v[]) { v[0] = 9 * v[0]; } int main () { int x, v[2]; x = 678; edit1 (x); printf (" x: %d\n" , x);…
-
2
votes1
answer59
viewsSegmentation Fault na strcat()
Recently I started learning about function strcat() and developed the code below, but I’m encountering a Segmentation fault: #include <stdio.h> #include <stdlib.h> #include…
-
2
votes0
answers68
viewsHow to solve libxml2’s Leak memory problem?
I am making an application, but I am having problems with the Leak memory when I use libxml2, already removed all the code to isolate only libxml2 and still have the Leak memory error when I use…
-
2
votes1
answer105
viewsHow to send a dynamically created matrix as a parameter to a function?
In the execution I am developing I try to pass a matrix created dynamically created with the function malloc, but in doing so the compiler points to type incompatible with pointer. #include…
-
2
votes1
answer61
viewsRecursion problem, C language
I have a problem, in a code I found where it receives a string from the user and returns it reversed, doing this recursively. However, I do not understand why the function made can actually do this.…
-
2
votes1
answer45
viewsCompile linux kernel module
Hello I’m studying about operating systems, through the book: fundamentals of operating systems. La in cap. 2 talks about kernel modules and shows an example: simple. c #include <linux/init.h>…
-
2
votes1
answer2269
viewsUsing stack concept to invert words
I am doing a work of Algorithms and Data Structure, which uses the concept of stack to do the inversion of words. However, when I am compiling the program, it is pointing out some errors that I do…
-
2
votes4
answers801
viewsHow to use switch in C?
I have to understand this code that my advisor gave me. The opt after switch is mandatory? The command break too? Why doesn’t it appear after the options case '?' and default? if( argc <= 1) {…
-
2
votes1
answer75
viewsMy C code contains some errors (Data Structure List)
I created a Music Player for a Data Structure discipline using Double Chained and Circular List. However, you are showing some errors and I am not seeing where. Could someone help me ? Maybe it’s…
-
2
votes1
answer69
viewsHow do I use the semicolon in the "for" command?
What’s the difference between a for ending with a semicolon and a for ending without a semicolon? Example: for(i=0; i<=10; i++)**;** //Termina com ponto e vírgula// Example: for(i=0; i<=10;…
-
2
votes1
answer39
viewsConfusion in access to vector size in C bytes
In the code below: #include <stdio.h> void testaTamanhoVetor(int vetor[]) { printf("tamanho do vetor em bytes na funcao: %zu", sizeof(vetor)); } int main() { int a[10]; printf("tamanho do…
-
2
votes1
answer1503
viewsProblems using setlocale() in c
Hello. I’m new to the community so if I’m doing something wrong please correct me. I’m starting to program in C, and I’d like to be able to accentuate my programs. I found materials about it on…
-
2
votes1
answer60
viewsReading numbers in C
I wrote this code to read multiple numbers on the keyboard. I want the reading to end when the user presses Enter. But when I press Enter, he keeps waiting for new entrances. #include…
-
2
votes1
answer55
viewsFactorization algorithm in C
When creating a number factor algorithm with while I see that by input of the number 21 onwards, the result is wrong -negative. #include <stdio.h> long int i=1, ii=1, num, fat=1, somatorio;…
-
2
votes1
answer44
viewsHow do I return a string from a char function? The returned value is NULL
I am having problems with creating a char function that returns a string typed by the user. I call her in a registration method and try to play for the struct variable. cadastrarLocacaoNome();…
-
2
votes1
answer89
viewsFunction that takes a string and converts it to uppercase letters gives error
My code performs double loop for and no longer executes even what I put after the function call stringToUpper() within the main(), or what I put after the loop for. #include <stdio.h> #include…
-
2
votes1
answer148
viewsChanging letters in C
I have a question, I’m making an algorithm that takes the phrase of the user that has no meaning, as if it were a code, to solve has a key that is the letters that most comes out of the Portuguese…
casked 6 years, 7 months ago Henrique M 87 -
2
votes1
answer41
viewsHow to improve the performance of a program by dividing executions into C-linked processes?
int main(int argc, char ** argv) { int i,j; uchar *image; camera c; point eye; point lookat; int samples; int s; float rcp_samples;// = 1.0 / (float)samples; //char fname[20]; //ray * rays; //color…
-
2
votes3
answers100
viewsPrintf does not print inside the while
the purpose of the code is to print the values of linked lists. Example of what the list looks like: L->[3]->[4]->[5]->X, should print 3, 4, 5. However. typedef struct lligada { int…
-
2
votes1
answer395
viewsCalculate Factorial Array using Thread’s
I’m having problems in the following exercise Write a program that, given a vector with the first 5 numbers primes, pitch 5 threads. Each of them will calculate the value of the factorial of one of…
-
2
votes1
answer198
viewsError in one of the program functions calculating a factor
I can’t fix the error of the last "factorial" function, which in this case would be the factorial at the bottom of this calculation: Program: #include <stdio.h> #include <conio.h> double…
-
2
votes1
answer519
viewserror: assignement to Expression with array type
I am trying to compile the code below for a list of exercises of my course introduction to programming but the codeblocks presents the error quoted in the title when I try to compile the code.…
-
2
votes1
answer150
viewsProblems with the Realloc
Good afternoon, I’m having difficulty creating a program that increases the size of a structure called list , similar to an array, whenever the occupancy rate of this list is more than 80% filled so…
-
2
votes1
answer1214
viewsHow to copy values from one vector to another quickly
I’m making a question that the number of elements in the vector are in 10 6 and just wanted to copy certain element to it only that I did the normal way, but common, there is another possibility if…
-
2
votes1
answer44
viewsHashtable: Segmentation fault when inserting - C
I am trying to implement a hashtable, in which the table would be an array of "buckets" in which each one contained user information, my code: #define tam_inicial 23 typedef struct user{ char…
-
2
votes1
answer13961
viewsFibonacci sequence in C
I’m doing a college exercise where the user must enter a number and the program must return the Fibonacci sequence. However, according to the teacher, it should start at 0 (ZERO), but my program…
casked 6 years, 6 months ago tspereirarj 49 -
2
votes3
answers77
viewsMicro class system in C
What I would like is to automatically initialize a struct that receives function pointers. For example: struct teste{ int x; int y; int (*soma)(int, int); }; typedef struct teste Teste; int soma(int…
-
2
votes1
answer68
viewsCan anyone tell me what’s wrong with this code?
I am creating a function that receives and breaks a string into several, depending on the delimiter(s) chosen by the programmer. So I have: void split(const wchar_t* text, const wchar_t*…
-
2
votes1
answer1586
viewsHow to remove a struct stored in c file?
I don’t think I explained it well in the title I have a schedule code where I can add contact, edit, list and is stored in a calendar file.txt only that I’m having trouble removing a contact that…
-
2
votes1
answer1711
viewsSimple text editor in C
I have the following exercise proposed: Make a program that mimics a text editor. Initially you will read the data typed by the user (lines of text) and create a vector in memory where the texts…
-
2
votes1
answer1360
viewsTurn lowercase into string
I need to do a function that takes two strings, and switch places both. But if you have a capital letter in the first one, at the time of converting you need to go to lowercase. I tried to do, only…
-
2
votes1
answer276
viewsHow to modularize the following code C
Below follows a code for date entry by the user and validation of it, but would like to modularize it. I don’t know if there is a possibility to use it outside of the box, or in an external file…
-
2
votes1
answer263
viewsHow do I pass the first char address of a string to a function to write to it?
The problem is this: I made a function that takes the output of a given OS command and stores it in a string. The idea now would be to declare a single char string in my main function using malloc,…
-
2
votes1
answer318
viewsHow to print tree with indentation proportional to the depth of the node in C?
I need to adjust this code so that the tree is printed with margin indentation proportional to the node depth, and that it prints a character ' - ' to represent each NULL. Anyone can help? If I have…
-
2
votes1
answer665
viewsConvert File string to Float
The program below should take the data written in a file . txt, show on screen and do the general average calculation. the data in . txt are being saved in the following format: Student: Bruno First…
-
2
votes1
answer36
viewsProblems in reading and organizing a C matrix
I have two files .txt, and each has a 2x8 matrix. I need to read these files and compare them, row by row, and when the line of both is equal, add to a counter. However, the problem I’m facing is…
casked 6 years, 5 months ago user117001 -
2
votes1
answer54
viewsOutput condition on do-while in code C
I need the user to enter the numbers 1, 2 or 3 to choose the locations, and if not select one, ask again. But when entering the number 0 or 4, for example, it returns to the start screen (that would…
-
2
votes1
answer1652
viewsProgramming C - Swap matrix elements
My code below should exchange the elements of the matrix, if it is 1 will exchange for 0 and if it is 0 will exchange for 1. However the printed matrix is with all elements 0: #include…
-
2
votes1
answer90
viewsHeader files in C++ using more than once
I am developing a cross-platform project (Windows - Linux - Macos). During its development and while generating documentation (via Doxygen) I realized that there are many files *.h to be called by…
-
2
votes2
answers161
viewsPointer for C functions is not calling
I’m having a problem with function pointers. I declared the pointers and stored them in an array, but when calling the functions through the pointers the compiler has an error that I have not yet…
-
2
votes1
answer45
viewsHelps with understanding cellular automaton code
I would like you to help me understand a code for calculating and presenting cellular automata that I found on the Internet. The code in question is as follows:: #include <stdio.h> #include…