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
-
5
votes2
answers761
views -
5
votes1
answer1118
viewsRead file in C
I am doing a project in C, which is necessary to create and read a file. I am having difficulty implementing the reading. In reading I tried to apply fgets(), fscanf() and the fread(). But none…
-
5
votes2
answers1763
viewsComparing user typed variable with file variable
Inside of my file arquivo.txt I keep two strings "nome" and "senha", They lay one on the other. I need to take the name and password entered by the user and compare it with the name and password I…
-
5
votes2
answers10981
viewsConcatenate char variable text in printf
I need to concatenate the name of the person (variable) with a text. Following the logic, it would look like this #include <stdio.h> int main (void){ char nome[6]; printf("Ola! Insira seu…
-
5
votes1
answer709
viewsWhy is strcpy() insecure?
I’m reading about secure programming, and I read that function strcpy(), of the C language, is an example of insecure. I also read that there is a secure version of this function, which would be the…
-
5
votes2
answers513
viewsIs there a difference between compiling from the linux terminal or from the IDE?
I’m programming in C in the linux for a semester now, and I always come across people who call themselves better programmers because they compile and run the program through the terminal. However,…
-
5
votes1
answer1532
viewsHow to calculate months of a year from a decimal number?
#include <stdio.h> #include <stdlib.h> int main() { printf("\tPrograma para saber quanto demora a tornar-se génio!\n\n"); float tempo(int horas); float converter(float x); int num_horas;…
-
5
votes2
answers859
viewsInvert array (vector) without an external function, 'manually'
Friends, I always invert vectors using an auxiliary in an external function (I think the standard way), however until recently a friend told me that had a way to invert vectors without using an…
-
5
votes1
answer426
viewsWarning compared between floats how to proceed
In an exercise I did, you are asked to make a compound interest calculation with for for the values of 5%, 6%, 7%, 8%, 9%, and 10%. As I could not use a check per counter being the counter a type…
-
5
votes1
answer1139
viewsClose console window in C
I need to create the old game. I want to know how to close the black window that appears without having to click any key, for example: When running the program appears: 1 to play 0 to leave If the…
-
5
votes4
answers6903
viewsGenerate random numbers that do not repeat
How can I generate a large sequence of random numbers that do not repeat? I have to generate 10,000 numbers from 1 to 1 million and store them in a file and they can’t repeat themselves. However…
-
5
votes2
answers1808
viewsAssign a value to the pointer and multiply (directly)
How do I multiply the pointer so I assume a value to it? #include <stdlib.h> #include <stdio.h> int main (void) { int a,*b,*c,*d; printf ("\nInforme um valor: "); scanf ("%i",&a); b…
-
5
votes2
answers866
viewsChar pointer or char array?
There’s a program that I picked up at a company, where pointers are used to char, guy char*, and then allocated a memory for it with the malloc, done the operations and at the end de-located that…
-
5
votes2
answers180
viewsWhy does the statement "char *argv[]" work in the main rg, but not in the body of the code?
Why when I use the declaration char *argv[] in the int main(int argc,char *argv[]) works, but when I try to use it inside the body of the code with char *argv[]; it doesn’t work? The error below is…
-
5
votes2
answers601
viewsHow to take the path of the open executable in C
How can I capture the path of the executable in C and place it inside a string?
-
5
votes1
answer350
viewsHow to make a process wait for 'brothers'
Hello. I need to create a process tree, until the moment what I was able to do was create a side of the tree, kill everything and then create the other side. But I need to raise the whole tree first…
-
5
votes2
answers1449
viewsPutting and comparing dominoes in order in C, using list or not ( if you can without)
The program asks to check if you have equal dominoes ( if you have at least one possibility to merge data 12|21) and asks to show an order that reaps the basic rule of the Dorians ( 12|24|45|53 );…
-
5
votes4
answers16290
viewsHow to remove spaces from a string in C?
I want to remove the spaces of a string, example: Pedro Henrique Ribeiro Would be: Pedrohenriqueribeiro The code I made, it takes away the space, but it duplicates a letter: #include…
-
5
votes1
answer558
viewsHow to access the indexes of a very large vector in C?
I have a problem that I have to assemble a vector (vet2[50]) with the sum of a large vector (vet1[100]), this vector vet1 is provided by the user and the sum if provided by: vet2[0]=vet1[0]+vet1[1]…
-
5
votes1
answer147
viewsIs it possible to "simulate" C++ Templates in C?
Taking a stack type data structure with array for example: typedef struct stack_s { int top; int item[STACK_MAX_SIZE]; } stack_t; Doubt appears when for some reason I want to use a stack with…
-
5
votes2
answers724
viewsDelete a space allocated by malloc
First I allotted 6 spaces of 52 bytes belonging to a struct in memory: lista = malloc(6 * sizeof(registro)); In practice to access them via pointer is done: lista[0], lista[1], lista[2]... And how I…
-
5
votes2
answers5592
viewsVariable Static and #define
What is the difference between defining a variable static and use the #define in C? Apparently the two have the same function, right?
-
5
votes1
answer821
viewsReduce a string in C language
How do I reduce the size of a string in C? In my program it is implemented as follows: char nomeString[] = "nomedoarquivo.txt"; I intend to cut the ". txt" of the end of the string.…
-
5
votes1
answer79
viewsType modifier: Type modifier
The type modifier register I have instructed the compiler to store the variable directly in the registers, however I do not see much its use in codes, this put, I have the following doubts: In what…
-
5
votes1
answer1182
viewsStatic functions in C
I noticed that some libraries use functions and static variables, for example static int sum(lua_State *state). This function belongs to a library that will be compiled into the language Moon. But…
-
5
votes1
answer446
viewsClang has Character error Too large but Visual Studio builds normal
I’m having a hard time understanding why the Clang presents the error message Character Too large for enclosing Character literal type when trying to execute the code: char c = 'ç'; while Visual…
-
5
votes2
answers498
viewsHow to assemble a list of generic objects in C?
In many higher-level languages it is possible to have a structure or a collection of data of various types, often the type is used Object for this. How to do the same in C? I mean, I don’t know the…
-
5
votes2
answers393
viewsIf array is the same as pointer, why does one need to be copied to a variable and another need not?
In that reply Maniero said that if the member of the structure was a pointer it would not need to copy the string into it. But arrays are not pointers? Why is it different?…
-
5
votes1
answer637
viewsHow is a "struct" organized in memory?
How access to struct? Can I put members in the order I want? How does the compiler know which part of the memory to access? What would this look like? struct { char ch1; short s; char ch2; long long…
-
5
votes2
answers464
viewsTip for C code optimization
The way I wrote the code below is very extensive. How to make the code more streamlined? void mostrasaida(char recebido) { int dadoA [5] = {252, 146, 145, 146, 252}; int dadoB [5] = {255, 201, 201,…
-
5
votes1
answer438
viewsHow to implement timeout in recv() in socket. h
I’m wondering if there’s any function to put a timeout together with recv() using Socket.h. Code example: // Variaveis UINT in_socket_handler; struct sockaddr_in server; // Cria o Socket…
-
5
votes1
answer850
viewsHow to encode and decode Base64 strings in C?
I need to encode (and decode) a JSON to be transmitted from the Web to a microcontroller. The JSON that I am sending is encrypted with the AES 128, but the cyphertext It contains non-printable…
-
5
votes2
answers292
viewsHow do I compare an input in char with an interval (0 to 9) without specifying individual conditions?
I’m doing a show that reads a string and want to ignore the spaces and letters that the user type (but I have to read the letters i and p and the mathematical symbols +-/*^). What I have achieved so…
-
5
votes3
answers8881
viewsHow to import functions from another C file?
In Java if we create other classes, for example: classe1 and classe2, if I want to call classe1 within the classe2 (because they are in separate files) I use import classe1. I made this code in C,…
-
5
votes2
answers458
viewsDoubt in displacement of bits in C
My question is regarding the following excerpt from a code: #include <stdio.h> int main(void){ int teste = 0, x0 = 0, x1 = 0, x2; x2 = 1; teste = ((x0|x2) | (x1|x2) << 1); printf("Valor…
-
5
votes1
answer476
viewsWhy use pointers as function parameters?
I already have a certain knowledge about pointer, but I wanted to understand why in most cases people use pointers as parameters in functions. Currently I have been studying algorithms through the…
-
5
votes2
answers6288
viewsGet the current date directly from the machine
I need to implement in my project (library system) the functionality of getting the date directly from the machine. I wanted in the format dia/mês/ano, to generate the fine for late delivery of book…
-
5
votes1
answer97
viewsStrange values in output when running newly compiled application
When I compile and execute this code on Linux, it shows a strange result. I believe it is memory junk. What is happening for it to show this result, and how I can solve? Command lines to compile…
-
5
votes2
answers9758
viewsPass matrix as pointer
I need to make the proposal: Elaborate a function that takes as parameters a pointer of an array, the number of rows and columns, and print the matrix elements. But I am learning pointers and having…
-
5
votes2
answers1366
viewsDiscover machine operating system in C
I need to do a function to clean the C screen running on Windows, Mac and Linux. I thought to do a function that: If the OS were Windows: system("cls"); If the OS was Linux or Mac: system("clear");…
casked 7 years, 3 months ago Gabriel Dantas 55 -
5
votes1
answer227
viewsReturn 0 on Linux and Windows
I am starting the ADS course and my programming teacher insists on using the return 0 at the end of the function. Most use Windows, I realized that the return 0 is required on Windows but on Ubuntu…
-
5
votes3
answers8939
viewsWhat is the correct way to declare a string in C?
There are several ways to declare a type variable string in C as: char *str; char str[]; char str[100]; char str[1][100]; What I’d like to know is, is, is there a correct way to declare a variable…
-
5
votes4
answers13368
viewsWhat are files with extension . cpp and . h?
What are these files with extensions .cpp and .h? How they interact with each other ?
-
5
votes5
answers11043
viewsRecursive Fibonacci printing
I’m having problems with the recursive function Fibonacci, in the exercise you ask to print inside the function or even using an auxiliary recursive function, but you can’t print in the main…
-
5
votes2
answers648
viewsHyperfactor in C by recursion
I’m trying to make a program with a recursive function to return a hyperfactor of a number in C, but the only value the function returns is 1. Where I’m missing? #include <math.h> #include…
-
5
votes1
answer199
viewsConvert uint16_t to int
I’m doing a project where a distance detector stores the distance in a variable uint16_t, and I need to turn it into int to make comparisons, but I can find nowhere how to do it. How to do?…
-
5
votes2
answers1728
viewsHow to receive a string and switch to check in C?
I have to develop an algorithm that gets the name of a place, for example, "School", and based on this, do a check of the string in the switch, and if it is "School", then it sends a message to the…
-
5
votes2
answers1175
viewsHow to get the representation of a positive integer in binary, using recursion?
I searched several sites, and in none I could understand how to make a conversion code using recursion from a positive integer to binary. I know there’s a function itoa but the challenge of the…
-
5
votes1
answer790
viewsStrictly binary tree
A binary search tree is strictly binary if all tree nodes have 2 children or none. Implement a function that checks whether a binary search tree is strictly binary. // Estrutura de dados typedef…
-
5
votes1
answer19547
viewsDecimal to torque converter in C
I’m doing a code in C for a college job in order to convert a decimal number to binary. But when the program runs, it always prints out 00000000, no matter what number I put in. Would anyone know…