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
votes2
answers70
viewsPointer pointing to another pointer, how to use the free() correctly?
When I have a pointer pointing to another pointer like: int *ponteiro1 = malloc(sizeof(int)); int *ponteiro2; *ponteiro1 = 5; ponteiro2 = ponteiro1; free(ponteiro2); And I use the command…
-
4
votes1
answer58
viewsWhat is the "-->" operator in C?
I’ve never seen this operator before, just another like ->, but it makes no sense in the context of that code. Code #include <stdio.h> int main() { int x = 10; while (x --> 0) { // x…
casked 4 years, 6 months ago Vitor Guimarães 367 -
4
votes2
answers263
views -
4
votes1
answer129
viewsHow to place a domino piece to the left of 6|6 in C?
I’m having trouble with the domino game I created. I can add the pieces to the right, but when I try to add to the left it does not perform as intended. Here is an example: Move 1 -> Table 6|6…
-
4
votes2
answers1473
viewsWhat is the difference between % and % in C?
What’s the difference between using the % and the %% in the C language?
-
4
votes1
answer1052
viewsBank Draft Algorithm in C using recursion
I am having doubts about a bank withdrawal algorithm in C. First of all it is better to pass the statement: Atms in banks are a great invention, but sometimes we need change and the machine delivers…
-
4
votes1
answer126
viewsWhy am I getting access to this pointer even after I’m free?
I have this program and theoretically it was not to lose the address of new after giving the free making the same inaccessible ? #include <stdio.h> #include <stdlib.h> typedef struct{…
-
4
votes2
answers92
viewsWhat term should I use in English for "dereference" a pointer
As you know in English the term Dereferencing is used to indicate access to the value stored at an address stored on a pointer i and..: int valor = 10; int *ptr = &valor; *ptr = 20; //…
-
4
votes2
answers385
viewsProblem with C matrices
I have to do a program that will read 4 grades from each of the 6 students in a class and store them in a matrix NOTES[6][5]. For each student, the arithmetic mean of the 4 grades should be…
-
4
votes2
answers588
viewsHow do I correctly access elements of a dynamic matrix via pointer?
As many know (I believe) a multidimensional matrix is stored in memory in a linear way, that is, each line of the matrix goes in memory one after the other. To illustrate I elaborated the following…
-
4
votes1
answer112
viewsLogic of these bit-by-bit operations
It’s been a long time since I wanted to start in the world of emulators, I decided to stop trying to make an emulator of a complex system and start with a very basic one, a CHIP-8 emulator, which is…
-
4
votes3
answers459
viewsStore values in matrices
I am using codeblocks, I am beginner in programming, starting with C, on account of college. The error is this: In the part of the code where it stores the value of the average of the student, only…
-
4
votes2
answers522
viewsDynamic allocation of vectors
Follows the statement: Make a program that reads keyboard numbers and store them on one dynamically allocated array. The user will type in a sequence of numbers, no quantity limit. The numbers will…
-
4
votes2
answers106
viewsFunction with a pointer?
Enunciation: A student’s grade is calculated from three grades awarded from 0 to 10 respectively to laboratory, a bimonthly evaluation and a final examination. The average three notes mentioned…
-
4
votes2
answers4332
viewsHow to identify a line break character in C?
Problem: Sometimes I get an entry like (and the entrance continues) other times as: (and the entrance continues) That is, I can receive an integer, or two, or three, and then then receive a string…
-
4
votes2
answers221
viewsHow to transform my code with static memory struct to C dynamics?
The exercise asks me to read information in a file, being them, Cpf, name, email and age of several people store in a struct, order in ascending order by age, if equal ages by Cpf, and print in…
-
4
votes3
answers1169
viewsVector sum problem in C
Vector sum problem, I’m trying to put the sum of the vectors directly into loop, but he is not doing the sum of all but duplicating the last vector, I tested the same code in Portugol and it worked…
-
4
votes1
answer73
viewsWhy is it that when I include my . h header, the . c implementation is not included as well?
I have three files, produtos.h, produtos.c and main.c. produtos.h is located in the folder "headers", produtos.c is located in "sources" and main.c is in the same folder as "headers" and "sources",…
-
4
votes1
answer203
viewsFunction "strcmp()" working without adding "string. h"
I wrote an algorithm in C that uses the function strcmp(). Even forgetting to add the string.h the algorithm worked. I would like to understand how it worked since I only found this function in the…
-
4
votes1
answer232
viewsfread(); problem in implementation
I have a simple problem. I can use the function fread normally to work with audio processing in C. In case I have 2 codes. The first reads a file . WAV (with fread) and saved in a .CSV. file This…
-
4
votes2
answers3414
viewsHow to count the number of times a number or more repeats within a vector in c?
I need to do this exercise and I’m locking in on the countdown. Make a program that reads an 8-position vector and checks for equal values and write them (each repeated number should only appear…
-
4
votes1
answer84
viewsEntry problem in loop comparing string
I can’t make it into the loop using only the char 'Anunciar', when you put something in, it starts the loop. What should I do? #include <stdio.h> #include <stdlib.h> #include…
-
4
votes2
answers211
viewsWhy is it wrong when I try to assign a value to the variable within a conditional operator?
I have the following code that should receive 4 numbers and tell which one is the largest. #include <stdio.h> int max_of_four(int x, int z, int y, int w); int main() { int a, b, c, d;…
-
4
votes2
answers439
viewsSize of type int with short and long prefixes in C
My architecture is Unix, so by default the size of type int is 4 bytes, so far so good. In Luis Dama’s book he states that short and long prefixes solve the problem for portability of programs…
-
4
votes2
answers250
viewsPrint struct data with read values from a text file in C
I’m trying to make a simple program to read data from a text file, store it in a struct, and print that data on the screen. The code I have is this:: #include <stdio.h> #define max 70 typedef…
-
4
votes1
answer58
viewsWhy does a function accept a reference instead of returning a value?
Consider the code snippet below: int num; printf("Enter a number: "); scanf("%d", &num); I understand that by passing &num to the second argument of scanf(), step the variable reference num,…
-
4
votes1
answer124
viewsHow abstract are pointers in C?
I have a vision, which from time to time seems wrong, that C pointers are simply and literally memory addresses. In this case it starts from a misconception that memory was a linear thing and…
-
3
votes2
answers1248
viewsHandling java/python/c directories
I have an A directory, and this A directory has several subdirectories, and in each subdirectory, it has a varied number of files. I would like to put all the files in a directory in the order they…
-
3
votes3
answers100
viewsRemoving cells at the beginning of a list
I have this little problem of removing an element from the beginning of a list, even doing the schematic in the drawing I could not. The strange thing is that it works with up to 3 elements, from 4…
-
3
votes1
answer117
viewsWhy can’t I use || for pointer?
I have the following code: int i=0; variable a; a.type = CHAR; a.name = malloc(sizeof(char)+1); while(*l->str++ != ' '); while(*l->str != ';' || *l->str != '='){ a.name = realloc(a.name,…
-
3
votes1
answer1403
viewsChained lists - add at the end of the list
I’m having trouble executing this code, whose goal is to add an element at the end of the list, the program is waiting for something that I don’t know what it is, then the program of the error. Some…
-
3
votes3
answers5625
viewsUsing Struct in Exercise C Language
/* Write an algorithm that reads data from "N" people (name, sex, age and health) and indicate whether you are fit or not to fulfill the mandatory military service. Inform the totals. */ #include…
casked 10 years, 8 months ago phpricardo 765 -
3
votes1
answer334
viewsProblems with AVL Tree Rotations
Hurrah, I’m developing code for an AVL tree. But I have rotational problems. Node structure: /*Node*/ struct Node{ int id; int height; char word[DIM]; struct Node *right; struct Node *left; }…
-
3
votes2
answers5124
viewsCopy Strings in C
I have the following two-dimensional matrix of strings. char matriz[linhas][tamanhoDaString] Through the strcpy I copied a string there. char *aux = "abc"; strcpy(matriz, aux); My goal was to put in…
-
3
votes2
answers103
viewsHow to create a vector2 in C?
I wonder if there’s a way I could create a class, to store 2 variables, for example, a Vector2, where I would instantiate and use it like this: Vector2 tile; int posX, posY; posX = tile.x; posY =…
-
3
votes1
answer197
viewsHow to link a class variable to c++ in lua script?
How do I access and set a class variable made in C++ passes to Lua? // C++ #ifndef SCRIPTSTORAGE_H #define SCRIPTSTORAGE_H #include "HTest.h" #include <luajit/lua.hpp> #include…
-
3
votes2
answers307
viewsEnd of Java Scanner input
This C code reads integers until Control-Z is typed (end of windows entry). void main(int argc, char *argv[]) { char line[100]; int sum = 0; while(scanf("%s", line) == 1) { sum += atoi(line); }…
-
3
votes1
answer849
viewsOperations with complex numbers in C - Root calculation of an equation by the Newton Raphson method
I have a problem with a language program C that calculates the root of an equation using the Newton-Raphson method, more specifically when the equation has complex roots. In my case the equation I’m…
-
3
votes2
answers3335
viewsPrint special characters on windows console
How to print special characters like 'is' and 'ç' on the windows console (printf)?
-
3
votes1
answer277
viewsDoubt in strcmp
I’m in doubt on a line of code: if(strcmp(novo->nome,aux->nome)>=0) How does your comparison occur? Being that the name is a char!
-
3
votes1
answer2570
viewsWork with Struct and print problem, change Struct and delete Struct
I have a work at the college to do that consists of creating a structure of "Library Register"(cataloging code, name of the work, name of the author, publisher, donated works of each area, number of…
-
3
votes4
answers9378
viewsAlgorithm Factorization in C
I need to create a program in C, which factors in any number the user enters. I wrote this code, but it doesn’t work completely because it only calculates once. I don’t want an answer ready, I want…
-
3
votes1
answer1642
viewsHow to rewind the file pointer correctly in Java?
Actually the problem is quite complex, but I’m going to try to give a notion that I think will be understandable. I have a method in an application that initializes objects to I/O in accordance with…
-
3
votes1
answer89
viewsARM atomic operations without Visual Studio
When programming in C/C++ on the x86 and x86-64 (AMD64) architecture and using the Microsoft compiler that comes with Visual Studio, there are two intrinsic functions to perform atomic operations,…
-
3
votes1
answer966
viewsArduino UNO restarts when using serial port outside the IDE
My Arduino UNO is rebooting when I use its serial port with a Python script. But when I open the serial terminal from the Arduino IDE and run the same Python script, it works normally. Why this…
-
3
votes2
answers93
viewsWhat is the difference between these expressions?
In the srand’s handbook man srand says srand has as a parameter a unsigned int, but when using without cast the compiler does not complain. It has some possibility of going wrong if not using with…
-
3
votes2
answers121
viewsCan I return a struct by initiating it into a Return in ANSI C?
Good morning guys, I wonder if I can do something like this... typedef struct Result { int low, high, sum; } Result; Result teste(){ return {.low = 0, .high = 100, .sum = 150}; } I know this…
-
3
votes3
answers5915
viewsStruct and chained list
I created a person-like structure and I intend to use it in a chained list, but the following errors appear: 'No has no Member named 'data', 'No' has no Member named 'Prox' and unknow type name 'p'.…
-
3
votes1
answer130
viewsError in Visual Studio
EDIT: Problem solved, after changing much of the code, not only in the functions mentioned here, the error stopped occurring. I’m getting this mistake and I have no idea what might be causing it,…
-
3
votes1
answer277
viewscho-han bakuchi
I’m trying to make C the game cho-han bakuchi. It is quite simple, the Japanese game consists of throwing two 6-sided dice into a cup, before the dice are shown the player makes the bet saying cho…
casked 10 years, 4 months ago Leonardo V. De Gasperin 713