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
votes2
answers141
viewsIs it recommended to use memset before strncpy?
Usually when we want to copy the contents of a particular string into another string we can use the functions strncat or strncpy. Using strncat The use of strncat to copy strings is kind of "wrong"…
-
2
votes1
answer526
viewsHow to implement a Recursive Merge
I have a Mergesort algorithm and I would like to implement the merge function recursively, it is not the recursive Mergesort function but its Merge function. Here is the code for the Merge Function…
casked 6 years, 4 months ago Erik Jhonatta 151 -
2
votes1
answer211
viewsSnake game, attempt of a beginner C/C++
Hello, I’m doing the snake game, but I’m doing it with a matrix, the way I’m doing it is to give prints and system("cls") quickly, but I’d like to know more efficient ways, like by expelling gotoxy…
-
2
votes2
answers181
viewsValues returned in comparison of strings in C
I was reading about some of the functions of header string.h in http://www.cplusplus.com/reference/cstring/ and I came across some comparison functions between strings (useful after all), such as,…
-
2
votes1
answer62
viewsProblems when printing the sorted number file
Guys, good night, I’m having a problem with this algorithm, I ask you to enlighten me with your knowledge. I apologize in advance if it’s hard to understand the code, I’m still in second period. The…
-
2
votes1
answer39
viewsDoubt regarding the inclusion of headers
It is considered a "bad programming practice" to include a header that had already been included in another header that included? Was it difficult to understand the doubt above? If so, please note…
-
2
votes1
answer131
viewsC pointers
Well, guys, I’m doing graph theory on C, and I tried to use dynamic allocation to create an array. Also, my code has a function to fill the matrix with 1 in the received indexes. But I have some…
-
2
votes2
answers62
viewsC - Remove result element
How do I remove the 0.00000 printings in the response of that program after the functions idealBrutus and idealOlivia are called in the function main? I realized that if, for example, I change line…
casked 6 years, 3 months ago Leandro Souza 113 -
2
votes2
answers77
viewsHow to modify the content of a root using a pointer?
How to modify the contents of a root using a pointer? Write a code in C that uses a variable with the name 'root', have the type 'float' and have the initial value 3.1415. In this same code, use…
-
2
votes3
answers2944
viewsWhile use within the if
I have to read infinite averages of students and if they are greater than or equal to 7 the student is approved , if not, he is flunked , and if I type -1 the program to and sends a message of…
-
2
votes1
answer428
viewsRead a number starting with 0
I’m having trouble reading a number initialized with long long long long valid; scanf("%lli", &valid); Input: 025 The variable valid will have as content 21 and not 25 If I change %lli for %llu…
-
2
votes1
answer807
viewsStable vs unstable sorting
What defines a stable sort algorithm? In this question has already been talked a little about what is stable and unstable ordering, but I still do not understand the advantage of using an unstable.…
-
2
votes1
answer896
viewsC / How to calculate the average in this program?
Hello, this program asks for a number of people, then stores information in the struct. My question is: How to make the program calculate the average height? Calculation is commenting #include…
casked 6 years, 3 months ago Diego Roney 127 -
2
votes1
answer70
viewsWhy is this C code not working (binary tree)?
Good morning, I’m trying to create a recursive function that traverses a binary tree and finds the largest integer contained in the nodes. My idea is to move to the function the pointer to the node…
-
2
votes1
answer71
viewsHow to print only once the name repeated?
For one or two names repeated, it works well, but if I make them all the same he repeats them ten times. I’ve tried using flag, but I can’t understand the reasoning. #include <stdio.h>…
casked 6 years, 2 months ago Lucas Correia 53 -
2
votes2
answers103
viewsUnexpected result
I wish to carry out the division of two integers and have as a result a floating point value. The following code works normally: #include <stdio.h> float divInts(int x, int y) {…
-
2
votes1
answer237
viewsHow to sort an array by the frequency of appearance of each element?
Not to delay too much I go straight to the point, I am trying to make a program for an exercise that possessed the following instruction: Build a function int ordenaFreq(int v[], int n) efficient,…
-
2
votes1
answer198
viewsC - How to pass an array in which it contains pointers to struct as a function parameter?
First I created a struct vector. Next I created a pointer vector, in which each element of this vector points to each element of the struct vector. Finally, I need to pass both (the struct vector…
-
2
votes1
answer1942
viewsSort list on in C
My problem involves reading data from a text file, where is provided the CPF, name, email, age, sort using list sort in ascending order through age, if you are equal age sort by Cpf. But I’m having…
-
2
votes1
answer50
viewsDoubt on a Language Issue C
Write a function that takes an array of 10 integers and returns to number of distinct numbers that make up the vector. For example, if the given vector is v = {3, 2, 1, 3, 4, 1, 5, 5, 2}, the…
casked 6 years, 2 months ago Vagner Wentz 481 -
2
votes2
answers111
viewsPointers and matrices catching something unexpected
#include <stdio.h> int main() { int vetor[][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; int valor= *(vetor[1] + 1) + **(vetor + 3); printf("%d", valor); } The code above was taken from…
-
2
votes1
answer238
viewsHow to pass a dynamically allocated struct to a C function?
The program must dynamically allocate the struct and pass it as parameter. #include <stdio.h> #include <stdlib.h> typedef struct cadastro_de_mercadoria{ int codigo; int estoque; }…
-
2
votes3
answers5610
viewsFunction that checks whether a vector is in ascending order
I’m doing an exercise that says: Critique the code of the following function, which promises to decide whether the vector v[0.. n-1] is in ascending order. int verifica (int v[], int n) { //n é o…
-
2
votes1
answer548
viewsStack Exercise - String with Trash
Write an algorithm, using a Stack, that inverts the letters of each word of a text finished by a dot (.) preserving the order of words. By example, given the text: THIS EXERCISE IS VERY EASY. The…
-
2
votes1
answer84
viewsHow to assign character array in a structure?
The program reads 10 films, each film has gender name, and age rating, then lists; I’m having trouble assigning matrix string (I think it’s just that mistake) #include <stdlib.h> #include…
-
2
votes1
answer90
viewsWhy is my server code not working with Ipv6?
I recently wrote a small C server using the sockets API from UNIX only for some tests. The program works perfectly with Ipv4, but the same does not happen with Ipv6... Follows the code: #include…
-
2
votes1
answer1048
viewsCompare Strings with Struct Array in C
I am trying to search a struct vector to return a list from the sex variable, but at string comparison time the list is not returned. complete code: PASTEBIN void consultar_registro() { struct…
-
2
votes1
answer130
viewsOptimization with GCC
Recently I was wondering if it is possible to compile with some flag optimization, avoid copying two arrays for the section .rodata? Thus, memory addresses would be equal, example const char str[7]…
-
2
votes1
answer57
viewsWarning: "No local application has been provided. You can set it in the Run menu, Parameters" Dynamic DLL Creation Problem in C++ in DEV++
I am trying to create a DLL with the code that the teacher passed, but it does not compile correctly. Keeps appearing the warning: "No local application provided. You can set it in the Run menu,…
-
2
votes2
answers1472
viewsSwap letter by number in C
I’m trying to program a phone algorithm with the old keys where the user will enter the letters as input and output will return me in the form of numbers. Note an example below: Input: Hello-World…
-
2
votes2
answers142
viewsError summing each row of a 5x3 matrix
Hello, I’m having a problem adding up each of the lines of my matrix and storing in a vector my code is like this: #include <stdio.h> int conta(int * matriz[5][3], int * vet) { for (int i = 0…
-
2
votes1
answer284
viewsStack operations
I am trying to do operations using stack but at the time of allocating the results in the previous position in stack is that I am not getting, because the result of operation is not allocated in the…
-
2
votes2
answers134
viewsProgram completion condition in C!
I have a program in C where the output should be the average of the numbers typed and how many of these values were typed are larger than the average. the program receives up to 100 F values, where…
-
2
votes1
answer49
viewsError to delete the first binary code entry
I found this code on the Internet only it has an error: when I register one user and try to delete it shows that it has been removed, but when I open again the program it is still there. This error…
-
2
votes0
answers56
viewsBehavior of refresh (ncurses)
I was recently studying the ncurses library and I came across a question: What exactly should the refresh function do? Researching a little I understood that she should update the screen, showing…
-
2
votes1
answer94
viewsIpv6 server accepting Ipv4 connections
I wrote a server in C using the API socket UNIX for some tests and I ended up encountering a "weird" problem: The server is cutting connections Ipv4 being that it was programmed to accept only…
-
2
votes1
answer109
viewsProblems with 2 vectors joining
I have a problem joining two sets of integer numbers into one vector, without repeating numbers that are in Set A and Set B. The following error is shown in row 13: error: Unknown type name ?bool';…
-
2
votes1
answer51
viewsUnique elements of a matrix
When reading an order matrix n x m where n and m are greater than 0 and minor or iguas at 10, I want to read the elements of this matrix and verify which are the unique elements of this matrix, but…
casked 6 years ago Gabriel Rezende 21 -
2
votes1
answer59
viewsBinary file being misspelled
Creating the binary file: #include <stdio.h> int main(int argc, char const *argv[]) { FILE *BIN; BIN = fopen ("BIN.bin","wb"); if (BIN!=NULL) { for (int i = 1; i <= 100; i++) { fwrite(…
-
2
votes1
answer75
viewsHow to make a string to be "transformed into a number"
I have an exercise to make the user type a word and it is transformed by its corresponding numbers from the ASCII table. EXAMPLE: sara would print 115 97 114 97 that’s the code: OBS: I put a fixed…
-
2
votes0
answers321
viewsRemove accent from a string in C language
I’ve got a college paper on Threads and competition control (Openmp) in C, which is giving me a bit of a headache. The job is to take a text from any file and separate it between Threads producers…
-
2
votes1
answer72
viewsEntering an arithmetic expression instead of an integer in C
I’m new in C and I made a very simple program that takes two numbers and prints the sum of them: // Programa que faz uma soma simples #include <stdio.h> // Função principal do programa int…
-
2
votes1
answer84
viewsDoubt - Dynamic list
I have the following structure for my dynamic list: typedef struct DataNode { int id; } DataNode; typedef struct Node { DataNode data; struct Node *Next; } Node; typedef struct List { int size; Node…
-
2
votes1
answer180
viewsOn the inclusion of headers (.h) and due compilation
Assuming I create a file .h for the specification of a function func. h #ifndef FUNC_H #define FUNC_H int xPy(int x, int y); #endif //FUNC_H and then created the implementation of this function in a…
-
2
votes3
answers80
viewsDo I need to re-allocate a structure in case I clean up just a part of it?
I have a struct who owns nome and horário for appointments. typedef Struct{ char nome[20]; char data[20]; }Dados; I make the statement: Dados *dados_cliente[quantidade]; I make the allocation…
-
2
votes1
answer60
viewsCalling C# method in C
I am trying to import a DLL generated via C# in C. I’m using the methods LoadLibrary to load the DLL, but when using the GetProcAddress the return is always null. I used the GetLastError and the…
-
2
votes1
answer347
viewsUsing "bytes" and "bits"
What use bytes and bits? I’m reading some C and C++ programming books that talk about bytes and I wanted to know what the use is or what these terms are for. For example, this table below talks…
-
2
votes1
answer133
viewsWhat is the effect of the bind() function on a client code?
I was wandering through Google Images behind a state diagram for server and client model and I ended up finding this here: I aroused curiosity regarding the image above due to the fact that the use…
-
2
votes2
answers105
viewsTrying to understand c/c++ pointers
Hi guys I’m new to the stack and it’s like this: I’m studying pointers and I made the following code: typedef struct { char nom[256]; int size; float value; }tdados; // criando o tipo tdados com…
-
2
votes1
answer41
viewsProblems with the malloc function
I’m working with the library Fuzzy, she uses the operator "new", but I wanted to replace it with the function malloc. When replacing I got no response on the serial monitor. Can anyone tell me what…