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
answer196
viewsIs it possible to open the file for writing and at the same time open for reading without before closing in C?
Not a good programming practice? void leitura(FILE *arq) { if((arq = fopen("dificuldade.txt","r")) == NULL) printf("Erro ao abrir o arquivo\n"); else { //linhas de codigo fclose(arq); } } void…
-
2
votes2
answers716
viewsCount number of cells in a chained list
I made the following code to count the number of cells in a chained list. But it is giving segmentation failure (use Linux). I wish someone would help me. #include <stdio.h> #include…
casked 5 years, 7 months ago Dalison Sergio da Rocha 19 -
2
votes2
answers109
viewsC Programming - Two-Dimensional Matrices
**Matrix Print Error.Cannot generate matrix lines. Note, without using another library** #include <stdio.h> int main() { int nlinhas,mcolunas; int matriz[nlinhas][mcolunas]; int n,m;//n…
-
2
votes1
answer106
viewsError searching row inside matrix
The exercise asks me to create matrices to store aircraft registration with some variables, done this, the program asks me to search all the information by entering the code. The problem is that…
-
2
votes3
answers111
views -
2
votes1
answer258
viewsHow to create an intersection with complexity in O(n)?
I need to create a function that makes the intersection between two vectors: vetorA ∩ vetorB and allocates the values found at this intersection in a vetorC! Rules: to) The complexity of the…
-
2
votes5
answers192
viewsCode executes a line that should be conditional
I am doing a job for college at C++ and, when performing an if/Else for a value of totalf equal to or different from 0, it is not obeyed. How do I exit display only a certain printf of correct…
-
2
votes1
answer70
viewsSerialize/Deserializar struct for sending via sockets
I have a struct that I would like to serialize/disallow to send in a connection via sockets using the function send and recover that struct with the function recv, what are the ways I can solve this…
-
2
votes1
answer243
viewsHelp with ROT-13 C encryption
Some letters of the encryption are passing from 'z', and going to symbols in the ASCII table, why is this occurring? #include <stdio.h> // CRIPTOGRAFIA ROT13 #include <stdlib.h> // A, B,…
-
2
votes1
answer499
viewsProblem with chained list in C
I am doing a college job where basically the Program should be done in C language using chained lists and have 3 options: Add music (beginning, middle or end of list) with name, band and duration;…
-
2
votes2
answers458
viewsError while clearing buffer in GCC (Ubuntu 18.04)
I was watching a tutorial of C, and appeared a part about buffer cleaning using the functions fflush and __fpurge. So far so good, but when I tried applying with __fflush, the GCC returns me the…
-
2
votes2
answers242
viewsFunction in C that deletes a given string
I need to create a function that deletes in s1 the first occurrence of s2. char *StrlDelStr(char *s1,char *s2) Example: char *s = "O rato roeu a rolha da garrafa"; StrlDelStr(s, "xy"); -> "O rato…
-
2
votes1
answer109
viewsOperation Logica in C
I’m trying to make a program to check if a certain word is a palindrome. I’m having trouble with a logical operation that isn’t returning what I expected. #include <stdio.h> #include…
-
2
votes2
answers268
viewsExercise: Pair or odd championship in c
I believe I’m not printing the result, because the vector condition is not met as a consequence of the value of the variable Winner, but I can’t see solution since I can only use these resources. I…
casked 5 years, 2 months ago Matheus Henrique 33 -
2
votes2
answers106
viewsMake a game continue or stop as the player chooses
In this game the player chooses a limit number and from this limit will be drawn a number and the user needs to hit it, I’m doing with function, but I do not know how to call again if the user wants…
-
2
votes1
answer167
viewsHow to calculate the distance of devices over WI-FI using force and signal frequency?
How can I calculate the distance of a device by wifi, using the strength of the signal of the same? I’m using tshark (wireshark) to perform this 802.11 scan, capturing only Prob requests (the moment…
-
2
votes1
answer59
viewsWhy is the result of my operation being printed printing 00 and not the actual result?
I’m practicing syntax in C language,a code about voting, wrote an excerpt of the code and went to compile to test, casting, and it didn’t work, I typed with int, double, float and nothing,%d,%f %i…
casked 5 years ago Cristiano M 33 -
2
votes1
answer356
viewsDynamic string allocation in an array
I have a problem to store a vector dynamically need to save 10 names but I’m not knowing how to access this data for later printing follows my attempt #include <stdio.h> #include…
-
2
votes1
answer175
viewsTest end of file in C
Hello, I have a problem and I couldn’t solve. while(!feof(arquivo)) { fscanf(arquivo, "%d[^,]",&result); fseek(arquivo,+1,SEEK_CUR); printf("%d",result); fscanf(arquivo, "%d[^,]",&result);…
casked 5 years ago Richard Santos 23 -
2
votes1
answer140
viewsArray problem in C, where is the error?
I have the following problem to solve: I arrived at this solution: #include <stdio.h> int main() { double numeros[99]; double resultante[49]; int i, j; for (i = 0; i <= 99; i++) {…
-
2
votes2
answers98
viewsWarning: format '%f' expectts a matching 'double' argument (en)(en)
My first post here and I would like to know, because when I compile my code it gives an error saying the format %f expecting a double, whereas the f is used to float and the variable I’m putting is…
-
2
votes3
answers54
viewserror in percentage?
A very interesting problem, the first two if me return valid values, but the latter returns a value different from the desired one. What to do? #include <stdio.h> int main (void) {…
-
2
votes1
answer40
viewsDoubt about accounting for ' n' in C
I have to count the number of characters and line breaks in my file.I did it this way: The idea is to count the line break every time someone gives enter, but I can only use the getc. include…
casked 4 years, 7 months ago GratefullyDead 373 -
2
votes1
answer36
viewsI tried debugging for a long time, but I can’t correctly omit consecutive repeat characters
I’m trying to create code to omit repeated characters in a row. I don’t know what’s going on and I’ve tried debugging for hours. Anyway, I’m trying to locate occurrences of consecutive repeated…
-
2
votes1
answer55
viewsDoubt about pointer and matrix
Hello, I was trying to do an exercise in which you asked to print the address of each position of the matrix using pointer and I am in doubt if it is correct. I searched some videos on youtube and…
-
2
votes3
answers109
viewsCalculator does not print the correct value
Hi, I’m coming back to the C language after a while. I’ve always used Code :: Blocks, but now, I migrated to Vscode. When I try to print values, giant numbers come out, for example: n°1 = 15 and n°2…
-
2
votes2
answers209
viewsVowel count
I need to make a code that takes a string typed by the user, count how many vowels there are in that string and swap all vowels from that string to a letter that the user defines, I did almost…
-
2
votes0
answers57
viewsWhy is this C code vulnerable?
I’ve been doing some code analysis exercises and came across an interesting case. The exercise presents a C code with a function and asks what type of attack this code is vulnerable to. I couldn’t…
-
2
votes2
answers62
viewsVolatile and optimization
I’m studying about the type qualifier volatile in C language, and I took a test. In the attached image we have the comparison of two programs written in C. The one on the left has a variable without…
-
2
votes2
answers231
viewssizeof does not work to determine the size of malloc
Well, I was doing a data structure job when I came across the need to dynamically allocate a vector, however, even allocating the space needed for the structure, the value returned by sizeof is…
-
2
votes1
answer83
viewsI tried to make my program in C open already in full screen, but it appeared 'error: expected declaration specifiers or '...' before Numeric Constant'
I want my program to already open in full screen when I click to run. I researched if I had how to do this and saw some recommendations to put this code at the beginning of the program # include…
-
2
votes2
answers196
viewsCode to generate random number sequence does not work
I developed a C code to generate a sequence of random numbers to be typed by the user, but it’s the first time I make a source code of the type for a college job, and according to the research I did…
-
2
votes1
answer37
viewsProblem creating 2 n x m matrices in C
Good morning, everyone! I’m doing a program to create and add two matrices. First the number of rows and columns is entered, then the values of the elements and then the matrices are summed. However…
casked 4 years, 1 month ago Thiago de Oliveira Magdalena 33 -
2
votes1
answer84
viewsHow to resignify bytes without Undefined behavior?
Details In Assembly, C, C++, C# with unsafe and other languages it is possible to reinterpret binary code at the address as of different type from the original. Convert type int* for float* in C,…
-
2
votes0
answers58
viewsError: Stack Smashing Detected in C
I have to make a code in which the user will give me the size of the matrix and the numbers within that matrix, and the size of the matrix has to be greater than or equal to 2 and the numbers…
-
2
votes0
answers53
viewsWhat makes this C program unusable when compiled in different versions of GCC or Clang?
This C language program is compiled in all versions of GCC without any error message, but specifically in GCC 6.3 and 8.3, the executable produces totally inconsistent results. In GCC 8.1 and 10.2…
-
2
votes0
answers27
viewsConnection terminates when sending a message from the client to the server (c/c++ socket)
I am using the codes below to make a client-server connection. The client I am making myself and the server for the time being picked up on the internet. The connection between them is made and the…
-
2
votes1
answer62
viewsHow do I create a loop that allows you to cancel the previous order when it passes a certain value?
Good evening. The following language is MQL5. I am creating a robot for Metatrader 5. I created after many hours the following code. I made the comments in English just like in the tutorial because…
-
2
votes1
answer218
viewsCheck if it is vowel or consonant and if it is lowercase or uppercase without using ready-made functions
I am developing two functions in C language, the first to check whether a letter is a vowel or a consonant, without using any ready function. The first is working. The second function checks whether…
-
2
votes1
answer102
viewsMemory allocation for string array with malloc()
This code below asks for a num for the amount of strings I want to store in vetor which in this case is the pointer char *strings[num]. #include <stdlib.h> #include <stdio.h> int main()…
-
2
votes1
answer56
viewsI have trouble printing the output of a string array
Code: #include <stdio.h> #include <string.h> int main() { int i, j, k; char nomes[10][99]; for (j = 0; j < 2; j++) { printf("\nTurma %d:\n", j+1); for (i = 0; i < 10; i++) {…
-
2
votes1
answer64
viewsProblems with the realloc() function in C language
Hello guys! I am implementing a code to insert a kind of table into a pointer and relocate memory while the function add() is being executed, the function name() will be executed only once to set…
-
2
votes1
answer15
viewsProblem compiling Math. h
Good evening, when I try to use some function of Math. h and put as argument a variable and try to compile I get an error. Can you explain to me why this is happening? Follow an example code:…
-
1
votes3
answers23004
viewsHow to pass a struct vector by reference parameter?
My question is, what is the error of this passage? It seems that the passage (*dadosCliente+i) is incorrect, someone knows why? struct cliente{ char nome[50]; char endereco[50]; } void…
-
1
votes1
answer189
viewsHow to create a file open dialog with the SDL library?
I’m making a very simple audio player in C (on Ubuntu) for a college job, and I’m using the SDL library to create windows (graphical interface) along with the Sdl_mixer to play the audio. The…
-
1
votes1
answer172
viewsDo I get NULL from STRTOK?
Hello, I am using Strtok to split a string into words. My idea was to follow the word REMOVE deleted the next word from the text. void algorithm(node **root, char *line){ char *pch = strtok(line, "…
-
1
votes1
answer627
viewsInsert - Jump Lists / Skip Lists
I’m trying to implement the insertion of a node in a jump list, but I’m not making progress with the solution because I don’t know at what point I should add the Node. So far I’ve made this…
-
1
votes2
answers4640
viewsAverage calculation problem between int and float
I’m having a problem with an average calculation. I have a struct with 3 fields. The ones I’m looking for are average product quantity and unit value. I need to average all the products and their…
-
1
votes1
answer623
viewscloud9-Problem executing code
The following code: #include <stdio.h> void main() { int num = 123; printf("O valor de num = %d e o valor seguinte = %c", num, num+1); } Returns in Cloud9 terminal the following result: The…
-
1
votes2
answers3217
viewssplit an array into several parts
Is there any way to access only a specific part of an array in c? For example, in python it is possible for me to access a specific part of an array. array[10] = 1,2,3,4,5,6,7,8,9,10 array[4:8] =…