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
-
7
votes2
answers275
viewsDetermine how many "islands" a matrix contains
I need to create a program that receives as input a matrix size (up to 300 by 300) and the matrix values that will be stored (can be only 1 or 0). I must determine the number of "islands" (clusters…
-
7
votes1
answer72
viewsUse the anonymous typedef or not?
I was looking at some C codes and I came across something like this: Example: typedef struct { char nome[256]; } Pessoa; typedef struct Pessoa { char nome[256]; } Pessoa; There is some difference…
-
7
votes2
answers7494
viewsHandling of malloc() and realloc()
I still don’t feel completely confident about using the malloc() or realloc(), these two ways are equivalent? 1) int main() { int x=0; char *s2,*s1; s1=NULL; s2=malloc(200); while(x++<3) {…
-
7
votes1
answer2353
viewsAnalyze whether a number is even or odd
The program must do: Digite um Número: 12345 1 e ímpar 2 e par 3 e ímpar 4 e pra 5 e ímpar So far I’ve made the following code: void parImpar (int num) { int resto; while (num > 0) { resto =…
-
7
votes2
answers595
views"Operator" square brackets [] when creating the arrangement in C
Whenever I look for what the operator clasps [] makes, even in the tables that show all operators in C, appears that it serves to access an element of an arrangement. However, it is not always that…
-
7
votes2
answers212
viewsPointer to struct
I was studying pointers to struct, and I saw that it has two ways to use. can be: (*ponteiro).variavel Or: ponteiro->variavel According to what I read, when we put *ponteiro.variavel, because of…
-
7
votes1
answer145
viewsHow to exchange information in full-duplex mode?
Note the two codes below: Client. c: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <netdb.h> #include <unistd.h> #include <arpa/inet.h>…
-
7
votes1
answer102
viewsWhat is the difference between a global variable and a global variable Static?
What is the difference between a global variable and a static global variable? Example: #include <stdio.h> int numero = 5; static int static_numero = 5; int main(void) { printf("numero: %d…
-
6
votes1
answer12372
viewsHow to compile C file using Sublime Text on Windows 8.1 64 bit?
I installed the Sublime Text in Windows 8.1 64 bit. How to compile a *.c file through Sublime on Windows? Is it necessary to install a compiler and/or another program to alert code errors and create…
-
6
votes2
answers942
viewsFunction returns pointer to trash, and free locks the terminal
Could someone explain to me the reason when I give free in the pontaux Windows terminal stops responding? And why when I allocate pontmaior my result comes as memory junk? The function returns a…
-
6
votes2
answers1084
viewsHow to write a string in a stream using physical files?
When inserting in a text file the characters of a string in C, blank spaces are ignored. How should I make long sentences within a string have separate words? Follows the code: #include…
-
6
votes3
answers5076
viewsHow to pick up the arrow keys in C/C++?
Is it possible to pick up the arrow keys (famous arrow keys) from the keyboard? if yes, how?
-
6
votes4
answers8703
viewsProgramming Online in C?
I want to know if there is a website that allows to program online, I tried to use Cloud9 IDE, but I can not program in C, someone knows some site to program in C, without having to install any…
-
6
votes3
answers1655
viewsHow to verify which technologies the CPU supports at runtime?
I am writing a program for PC that has optimized function calls for SSE2, SSE3 and maybe SSE4. However, I cannot guarantee that the PC running the program supports these technologies and would like…
-
6
votes4
answers616
viewsTrouble finding prime numbers
Today in college I learned about the for and the while. However, the code I am trying to formulate does not run. It compiles but "Buga" after it puts the value. The code is simply for checking…
-
6
votes4
answers11111
viewsConverting float to char array in C/C++
I recently took a test and there was a question that asked for a number like 123.456 was shown as 321.456. I thought the best solution would be to convert this to an array of char and then create an…
-
6
votes2
answers1552
viewsIs it possible to implement a dynamic array within a C structure?
How is it possible to create a dynamic array within a structure Example typedef struct historico_de_fabrica { Hist_id_rolos rolos[1000]; //<- este array em vez de ter 1000 posições queria em…
-
6
votes1
answer11317
viewsFloat rounded in C
I need to return a value float with 1 decimal place, but is returning with the rounded value. I have the following code: float n1 = 4; float n2 = 9; float total = n2 / n1 ; printf("Media: %.1f ",…
-
6
votes1
answer5046
viewsClient/Server (Windows) with C Sockets
I’m trying to write a program written in C, which is able to upload a file or text to a particular server. I searched a lot on google but most of the tutorials are aimed at linux environment, either…
-
6
votes2
answers201
viewsError in keyboard events in Allegro
I’m doing a work of my course using Allegro as indicated. I need to capture the events of loose keystrokes on the keyboard, so I used the following: al_wait_for_event(evento, &ev); if(ev.type ==…
-
6
votes2
answers189
viewsAdd JNI Library Compilation with Maven or ant tasks
I am creating a Java project with native methods (JNI) without having to create three separate projects for it. My goal is to compile everything I need all at once. I use only one DLL/OS in this…
-
6
votes1
answer344
viewsData Alignment, Data Structure Padding and C
Can anyone explain to me how processing/compiling does padding? I don’t understand why the structure structc_t has a size of 24, shouldn’t it be 16 equal to structd_t? Note: Data on 64-bit Intel…
-
6
votes1
answer604
viewsRun Fullscreen program on Windows 7
Hello I have a project already finished, it was written in C language as I do so that it runs in fullscreen in windows 7? Do you have a library for this? I’ve been looking on the internet but I…
-
6
votes1
answer347
viewsinterpretation of quicksort
I learned Haskell, and now I’m starting to learn C. I’ve been trying to pass my quicksort code in Haskell to C but I haven’t succeeded. So I decided to look at some books and found the following…
-
6
votes1
answer736
viewsWhat are the practical differences in C and C++ code portability?
I have been reading some open-source C code lately and have noticed that many of them become quite complex and with enough #ifdef in order to make the code as portable as possible between different…
-
6
votes2
answers934
viewsHow to create an index file using B+ tree
I have a B+ tree that acts as the index of a data file. This index must be saved in an index file. A struct node or node of the B+ tree is: typedef struct node { void ** pointers; int * keys; struct…
-
6
votes4
answers274
viewsProblem checking prime numbers
I have to create a random number array in a range from 0 to 250, and show which are the primes. This is my code: #include <stdio.h> #include <stdlib.h> #include <time.h> int…
-
6
votes1
answer270
views -
6
votes2
answers403
viewsComputer buffer
I’ve read several places about buffers and there they say that it is a place in memory to store temporary values so they give an example like in C: char exemplo[10]; and say that this is a buffer,…
-
6
votes1
answer545
viewsHow to clone a list linked in c?
How can I make a linked list without being recursive, I have this so far. Code: typedef struct slist *LInt; typedef struct slist { int valor; LInt prox; }Nodo; LInt clone (LInt a) { LInt k;…
-
6
votes1
answer1276
viewsMulti Thread Socket Server - Java Server and C++ Client
I have to develop a Mini Server Socket Multi Thread (college work) in Java and need to make a Client in C, for example, can be in any language, but I chose these two. How do I send the Client values…
-
6
votes2
answers5045
viewsHow to check in C if the file is empty?
Good night, I’m working with C, and it turns out I have a function or method that you have to print to a file the data, the meal appointments,. In the method the system has to check if that file is…
-
6
votes3
answers22761
viewsCompile C in Sublime Text
I’m using Windows, and need to know how to compile programs written in C in this editor. No ubuntu is easier, but in Windows 8.1 I don’t know how to do it. I’m using Sublime Text 2, because he’s my…
-
6
votes2
answers475
viewsMalloc improperly reserving memory?
I am studying dynamic memory allocation and came across an error that apparently the compiler is not warning about. The code is very simple: int *ptr = (int *) malloc(sizeof(int)); ptr[0] = 5;…
-
6
votes1
answer217
viewsWhat is behind the malloc() dynamic allocation function?
What mechanisms the function malloc() uses in practice to manage dynamic memory allocation in a program?
-
6
votes1
answer838
viewsHow to print the variable name in C?
Example: I have an entire variable called menino, how do I print on a printf() the name of that variable, i.e. "menino"
-
6
votes1
answer286
viewsWhat is the best way to create a binary tree in C language?
Being a binary tree a set of records that meets certain conditions. I would like to know how best to implement a binary search tree in language C would be using a structure with head or without…
-
6
votes2
answers1608
viewsInfinite loop trying to calculate if the number is prime
I have no idea how I’m going to determine the condition of for for prime numbers. I always end in looping. #include <stdio.h> int main() { int num = 1, primo; do { printf("Informe um numero…
-
6
votes2
answers1679
viewsCalculate Body Mass Index in C
I’m doing a simple C-program to calculate body mass index. However, it is returning a different value (wrong) than a common calculator. #include <stdio.h> int main() { float height, weight,…
casked 9 years, 1 month ago user28062 -
6
votes1
answer27217
viewsRounding in C
I wonder how I could ignore rounding in divisions, for example: 4/3 = 1,33... ~ 1 | 5/3 = 1,66... ~ 2 Right? I wanted to make a program in C, that in these cases, the rounding is not done, because…
-
6
votes1
answer179
viewsWhat are digraphs in C?
Based on the question of graphs, what are digraphs? Why were they created? What are the sequences? Current compilers still allow you to use them?…
-
6
votes1
answer123
viewsWhy can I access a structure without the pointer?
When I declare a pointer to struct I can access members without entering an address struct, why is it possible? For example: struct exemplo{ int a ; }; int main() { struct exemplo *p; p->a = 10 ;…
-
6
votes1
answer1150
viewsRecursive analysis of a vector
QUESTION: Write a function recursive that analyzes the elements of a vector and returns one of the following codes: 0 Disordered elements 1 Elements sorted in ascending order 2 Constant elements 3…
-
6
votes1
answer518
viewsHow to make a program to calculate constant mathematical expressions
I have a job to build an algorithm that calculates expressions coming from a TXT file in this format. 10+20*(30)/ 25. I know this is a recursive descending analyzer, but I have no idea where to…
-
6
votes1
answer150
viewsIf is executed even with the condition being false
I have an excerpt from a function with the following code: printf("caminho: %d\n", t); printf("min: %d\n", min); if( min >= t && t != -1); { printf("oi\n"); min = t; printf("min:…
casked 8 years, 7 months ago vitor martins 73 -
6
votes2
answers691
viewsGets() function for float value
I wanted to use the function gets() for a value float, or a similar function.
casked 8 years, 6 months ago Pedro Carvalho 61 -
6
votes1
answer356
viewsWhat is * for in the expression "Foo* foo = new Foo" in C++?
I was looking into this question done in SOEN. There is teaching to instantiate a certain class. I was able to understand more or less how it works, because when I use my example, it is giving error…
-
6
votes1
answer670
viewsHow to use GOTO in C to implement finite automata?
It’s my first time using goto in programming and I made a simple code here to try to implement the automato (must have much better modes), but my code is crashing at the time of running, I do not…
-
6
votes2
answers1002
viewsBogosort - what is this?
What exactly does the bogosort sorting algorithm? Because many say he’s inefficient?
-
6
votes2
answers194
viewsHow to read the command line?
Let’s say I want to do a routine to automate the process of compiling a program. In general (language independent), you call compiler from the command line. For example: javac meuPrograma.class or…