Questions tagged as 'c'

2
answers

Why declare pointer to array if arrays are already pointers?

If a char array is already a pointer, why declare a pointer to the array? And what's the difference between char exemplo[10] and char *exemplo[10] ?     
asked by 08.10.2015 / 03:19
3
answers

Use free () without malloc ()?

Could it be a problem to use free() on a pointer that was not allocated with malloc() beyond the unnecessary itself? void funcao (int par) { char *palavra; if(par%2 == 0) { palavra = malloc(3*sizeof(char))...
asked by 29.07.2016 / 16:12
2
answers

Calculate the factorial by reference passage

I am studying pointers I am trying to calculate a factorial of a number, but the result is a totally different value than expected. Here is my code #include<stdio.h> #include<stdlib.h> void calulcafatorial(int num, int *fatorial);...
asked by 03.01.2018 / 11:34
4
answers

Generate random numbers that do not repeat

How can I generate a large string of random numbers that do not repeat? I have to generate 10 000 thousand numbers from 1 to 1 million and save to a file and they can not be repeated. Although the sequence is large, it has some repeating numb...
asked by 21.06.2016 / 05:11
5
answers

Concatenation in C

I'm doing an algorithm in C to turn off some machines. This is my algorithm: #include <stdio.h> #include <stdlib.h> #include <conio.h> main() { char vetor[2][15] = {"192.168.2.200", "192.168.2.201"}; for(int i = 0;...
asked by 19.01.2018 / 12:41
2
answers

How do I check if there is a special character or number in a string in C?

I'm confused in logic to see if you have other characters than alphabetic characters. I thought the following logic, but I think it is wrong: char nome[30]; scanf("%s", nome); int especial = 0; for(i=0; i<strlen(nome); i++{ if(!(nome[i] &...
asked by 11.07.2017 / 00:04
3
answers

Global variables recursion

I am learning recursion and I have doubts about using global variables, particularly I think a clumsy gambiarra , maybe you could be wrong. I made a code to add positive numbers and I used a variable called sum. I wonder if there are any other...
asked by 29.01.2017 / 21:41
3
answers

Invert string in C

I'm trying to invert a string into C but the function is cleaning it: for(i = 0; i < (int)(size/2); i++) { tmp = buffer[i]; //armazena o character inicial buffer[i] = buffer[size - i]; //Troca o character da ponta oposta buffer[s...
asked by 01.07.2016 / 20:27
2
answers

Doubt about pointers

This code creates array, initializes and prints, as well as adding, subtracting and multiplying arrays: typedef struct{ int nl; int nc; int **elementos; }MATRIZ; void criar_matriz (int, int, MATRIZ *); void inicializar_...
asked by 11.03.2015 / 23:46
3
answers

Why is an asterisk left?

I want the number of rows and columns in the output of my program equal to the given input . Why is the latter left over?? Code: #include<stdio.h> #include<math.h> int row = 0; char column = 0; int n; int main ( void ) {...
asked by 13.12.2016 / 03:06