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
answer96
viewshow to receive input from the user and write to a file
I am trying to receive several lines of input from the user (at most they will have 37 chars each) and write them in a file, but the result is the creation of the file with nothing there. My current…
-
2
votes3
answers3223
viewsHow to use the "fread" function in c to read a txt file string and store that string in an array?
Hello, I’m trying to read a block of bytes from a file. txt that contains a string for example, I want to store that string in a char array. #include <stdio.h> #include <stdlib.h>…
casked 7 years, 5 months ago Italo Zuckerberg 63 -
2
votes2
answers71
views -
2
votes2
answers136
viewsWhat is the difference between memcpy and snprintf
I see people using snprintf when I would use memcpy. I even did some tests and it worked with memcpy. Now I was in doubt of why to use one and not the other. And what the real meaning of the two.…
-
2
votes1
answer123
viewsError in recursive logic
My recursive function needs to calculate the power from b to N is giving error "Segmentation failure (recorded core image)", which can be? My job: int potencia(int b, int n, int a){ if(n == 0){…
-
2
votes2
answers2641
viewsFind lower vector value recursively
My recursive function needs to return the smallest vector, only it is always returning 0. What’s wrong with my logic? My job: int menor(int vet[], int i) { int m=0; if(vet[i] == 0) { m=vet[i];…
-
2
votes1
answer361
viewsImport multiple libs into a single include in c
Is there any way to import all libs from my program into one include as in other languages : import re, datetime, math ( Python ) ? After reading about pre-processing directives here ( Little is…
-
2
votes1
answer789
viewsHow to remove and rename directories in C language?
To create a directory I used the mkdir(const char*) function and to remove I tried to use remove(const char*),as below: void remove_diretorio() { char nome_pasta[10]; printf("Informe o nome da…
-
2
votes4
answers2189
viewsSum of primes in a range in C
My problem says to add the primes in a user-given range, including the ranges if these are primes. Example: ENTRANCE: 2 and 10 EXIT: 17 I managed to do that: #include <stdio.h> int main() {…
-
2
votes2
answers120
viewsHow to format strings and store them in a dynamic vector
In several parts of my code I need to use bash commands to run programs on Ubuntu. To do this, format the command using sprintf and then run with the system function. Ex: sprintf(sprintfoutput,…
-
2
votes2
answers1211
viewsExecute bash commands in C
I’m using the function system("comando"); to execute bash commands in a C program. However, I am having difficulty printing the value of a variable. #include <stdio.h> #include…
-
2
votes1
answer118
viewsType of char data needs space after quotation marks in the scanf
#include <stdio.h> #include <stdlib.h> void main(){ char elevador; int cod=0, a=0, b=0, c=0; while(cod == 0){ printf("\nElevador utilizado (a/b/c)? "); scanf("%c", &elevador);…
-
2
votes1
answer2788
viewsHow to properly use memcpy?
I’m trying to create a program where it will have two vectors : char vetor_origem[20] = "algoritmo"; char vetor_copia[20] In what can be seen, in the vetor_origem I have the word algorithm written,…
-
2
votes1
answer447
viewsGenerate PPM file
Hello, I have a code to generate a color matrix and a problem to make a sequence, but unfortunately I can not understand well the logic behind it. Enunciation: Create a color palette where each…
-
2
votes2
answers512
viewsError creating child - Process scheduling using Fork
Write a program in C/C++ called novel.cpp that does the following: The Father process creates a Filho1 process in 10 seconds and a Filho2 process in 20 seconds and then you’re running indefinitely.…
-
2
votes1
answer4013
viewsBinary file storage
In the program, I need to implement a structure that represents a student (name, age and enrollment). Using this structure, I have to write a program that reads the data of 5 students and stores it…
-
2
votes6
answers1851
viewsInterlink two strings into one vector
/** 5. Faça um programa que receba 2 strings (A e B) e retorne uma terceira string (C) formada pelos caracteres de A e B intercalados. Ex.: Se A='Quarta' e B='Segunda', a resposta deve ser…
-
2
votes2
answers155
viewsDoubt about char in C
What does that char* mean and those empty quotes""?: char *directionX = ""; char *directionY = ""; If you can help me I appreciate.
-
2
votes1
answer282
viewsProblem inserting elements in a queue
I made a function using the concept of static queue to insert an element, however, it is not running when I call it in main. I do not know if the problem is in her, in the main function or in the…
-
2
votes1
answer759
viewsWhat is a recursive method?
The variable resultado within the for is recursive? #include <stdio.h> int main(void) { int N,i; double resultado=0.0; scanf("%d",&N); for (i=0; i<N; i++) { resultado= 1.0 /…
-
2
votes2
answers1433
viewsInvert "string"
I have the following function: void InverterString(char *str1){ char aux[strlen(str1)]; for (int c=0; c<5; c++) aux[c] = str1[4 - c]; printf("A string1 invertida fica: %s", aux); } However, it…
-
2
votes1
answer57
viewsMysql Connector/C error
I’m having a C problem, while trying to include Mysql bookstore gave some strange errors that I didn’t find anywhere. I downloaded the bookstore on official website for Win32-x86 (ZIP) and installed…
-
2
votes1
answer76
viewsWrite member access to a pointer structure instead of using the "->" operator
How would you write this assignment: p1->caracter='B'; otherwise using * instead of ->?
-
2
votes2
answers6394
viewsSum of even numbers and multiplication of odd numbers in a range
Read two numbers being y greater than x, calculate the sum of the numbers pairs of that range of numbers, including the numbers typed; calculate and show the multiplication of the odd numbers of…
-
2
votes1
answer826
viewsHow to configure the amount of exponent numbers in scientific notation in C++
My code is giving the error in the presentation of the scientific number, because it always appears with 3 decimal places being necessary only. #include <stdio.h> int main(){ float num=0.0;…
-
2
votes1
answer273
viewsUsing the switch function in C++
The function switch and I don’t know what I’m doing wrong marcos there appear "landmarks and cool" and put murilo "Nice and cool". I’m doing it like this: #include <stdio.h> #include…
-
2
votes1
answer619
viewsWhat is the difference between %d and %i in printf and scanf in C?
What is the difference between %d and %i no printf and in the scanf, in the C language?
-
2
votes1
answer77
viewsWhy does this work? pointer = (struct a *)&b;
struct a { int a; int b; }; struct b { int a; int b; }; struct a *ponteiroa; struct b b; b.b = 20; ponteiroa = &b; //Isto não dá certo ponteiroa = (struct a *)&b; Why is this (struct a…
-
2
votes1
answer59
viewsWhy am I only able to manipulate files with pointers?
In the statement I always have to put FILE *Arq; If I put it without the * it presents an error. Why?
-
2
votes2
answers10163
viewsHow to make the rest of the division of a float by a number in c?
I am beginner in programming in c, I have here a problem the exercise and calculate the average of the odd in a matrix that receives real numbers. However, I’m having the following mistake: error:…
-
2
votes1
answer77
viewsInsert function does not work
I am building a chained list to save a string with the following signature on the record: typedef struct Lista *Noticia; struct Lista { int hora; char *Texto; struct Lista *PN; }; And insert the…
-
2
votes1
answer319
viewsHow to fill an entire array with malloc(sizeof(int)) with some value
I have a problem, I have no idea how to fill this vector with some value, for example, I want to fill it all with -1 (start it all with -1). The problem here is that I don’t know exactly how big my…
-
2
votes2
answers4454
viewsWhat is sscanf() and sprintf()?
What is the purpose of the sscanf() and the sprintf()?
-
2
votes1
answer1082
viewsCompile C++ file in VS Code using external cmd
I can compile files in VS Code normally, but the files are shown in the terminal of the program, which does not allow the insertion of characters. How can I set up to be able to use a terminal that…
-
2
votes1
answer107
viewsPointer arithmetic in C
I am doubtful in a way to know the length of a vector without using sizeof: int n = *(&arr + 1) - arr; It is known that: arr is the type int ( * ) and (&arr + 1) is the type int ( * )[size].…
-
2
votes1
answer101
viewsSegmentation Fault function that changes the values of 2 strings
The following function changes (or at least should) the content of two strings void trocar(char *a, char *b){ char *novo = (char *) malloc(sizeof(char) * 10); strcpy(novo, a); strcpy(a, b);…
-
2
votes1
answer70
viewsThe entry point of a executable is the memory address of the main function?
hello. c #include <stdio.h> void main(void){ // << entry point printf("Hello World!"); } hello asm global _main extern _printf section .text _main: ; << entry point push message…
-
2
votes1
answer204
viewsWhat function allows you to open . txt file and run other functions in the contents of this . txt?
Which C language function allows you to open file .txt and run other functions in the contents of this .txt?
-
2
votes2
answers4669
viewsProblem with library Math. h (indefinite reference to `sqrt')
I’m having trouble compiling the code with the function sqrt() in the C language. Error: gcc exercicio_03.c /tmp/ccGVE8ez.o: na função `distancia': exercicio_03.c:(.text+0x142): referência…
-
2
votes1
answer50
viewsAlgorithm C. Why does the string "Why" return and does not return numerical values?
I wrote an algorithm in C to write on the screen ordered pairs of a function, with input of x integer numbers. int main(int argc, char *argv[]) { int x,i; x = -1; do{ system("cls");…
-
2
votes1
answer999
viewsHow to search for an element in a structure vector?
Good night! I am doing a work in C where I have to look for doctors by specialty, that is, I ask the user the name of the specialty to look for and I make a printf of the doctors of that specialty.…
-
2
votes1
answer54
viewsPresentation failing in binary tree
I can’t present my tree either in order or preOrden as in the example below the cursor just vanishes and waits for another instruction #include <stdio.h> #include <conio.h> #include…
casked 7 years, 3 months ago Lucas Alves 101 -
2
votes1
answer266
viewsInequality in C language
Data: Brutus is 1.84m and weighs 122kg and Olivia is 1.76m and weighs 45kg. IMC = peso/(altura*altura); IMC: 18,5 a 25 -----> Saudável I want to create an algorithm that prints how much MINIMAL…
-
2
votes2
answers203
viewsExplanation of recursive functioning
I’m at the beginning of system analysis studies and I’m learning programming language. In C language studies I started to see recursiveness and some codes that have recursiveness I get lost and end…
-
2
votes1
answer118
viewsProblem with linked list of dynamic C implementation
Hello, folks, I have two questions: Why can’t I print out any list? How do I scroll through a given list, without head and sentinel, backwards using this implementation? #include <stdio.h>…
-
2
votes3
answers161
viewsSize of a character array according to its addressing
Is the size of a character array given by its address or by the value of the variable? Example: char[1000] = "Exemplo Teste" The size of this variable is 1KB due to its addressing char[1000] or her…
-
2
votes2
answers1641
viewsPass pointer pointer as argument for a function
I want to create an array using pointer pointer, but I’m having difficulty passing the parameters. First I dynamically allocate the matrix using a function. And then I read. The program compiled,…
-
2
votes1
answer574
viewsError generating C calendar
was working on a program that generates a calendar for a month however it is not working properly with long years as in March 1004 the first day begins Wednesday and the last on Friday. March 1004…
-
2
votes1
answer462
views"unsigned int" and "int," what’s the fastest?
In language C, enter unsigned int and int, what is the fastest type? I know (think) that unsigned can store larger numbers why int reserve a bit (space) for the signal and unsigned no. But which the…
-
2
votes2
answers6936
viewsAverage C using vectors
I started my journey on C two days ago. I went to try to develop a function that averaged certain numbers of a vector. The function has some problem since it was to return the value of 4,5 and is…