All Questions

Tagged with
Filter by
Sorted by
Tagged with
0
votes
1answer
47 views

I am getting an error message when trying to split a string and put them into an array

I am trying to split the user's input and put each delimiter in an array. For some reasons, with the code I have here, I get an error message: called object type 'char *[10]' is not a function or ...
0
votes
1answer
31 views

How to make a compiler interpret a memory array with chunks of 8 bit (or diff in other case) while type casting void* to unsiged char* array in C

i am writing a program in which my data from a unsigned int* buffer needs to be converted to a data array of unsigned char* array, so that i can use it further. But if my buffer is initialized to 0, ...
-1
votes
3answers
34 views

Pass an array as an argument and print the array item in C program

I declared and initialized an array in main method of C program and defined a method to print the array elements, but it prints some garbage values instead of the actual value. I tried the following ...
1
vote
2answers
38 views

How can I define an array of scanner input in C not in main()?

#include <stdio.h> #include <string.h> #define line 4 int array[line]; //This works perfect int s = user input; //assume the user typed in a value and I stored the value in s; ...
3
votes
1answer
44 views

Passing Multidimensional Arrays into a Function

I need to be able to pass a 2D array into the scanning function after scanning for the size of the array. Everywhere I've looked has told me that you can't pass 2D arrays without dimensions into a ...
0
votes
0answers
42 views

Trying to create multiples small multi-dimensional arrays with malloc

I'm trying to allocate two multi-dimensional arrays from a struct with a function. Allocating the first works perfectly but the second fails, even though the code for the two arrays is exactly the ...
-3
votes
0answers
25 views

Trying to make a tiles game (“comparer wont read as intented after action”) [on hold]

Help pls i want to see if chain 1,2 and 3 are the same, but when i move a "tile" i cant compare my strings anymore p.s. i wrote a small backstory of whay it is im trying to do XD heres a smaller ...
0
votes
2answers
28 views

Structure in a Structure and Array

I have a few problems with the following assignments: a) Define a new data type tpos for storing the position of a solid in the two dimensional plane in single precision. Afterwards define another ...
1
vote
1answer
31 views

Sorting and Analyzing Arrays In C

I made a little dice game where I should get Grand if I throw 5 times the same number and a Poker if I throw 4 times the same number. My problem is that my code only work with "1" and "2" if I try to ...
1
vote
1answer
29 views

Dynamic Array of Strings Causes Segfault

I wrote some code to create a dynamic array of strings which is automatically resized once full. Even though there seems to be no issue inserting elements in it, I get a segfault when trying to print ...
0
votes
1answer
43 views

Create an array based on lines in a file

Firstly, I don't post here that often. So apologies if this is out of place. I moderate some forums so I understand why you would find it frustrating if this is in the wrong place or answered 1000 ...
0
votes
1answer
31 views

Modify a character pointer string array (char * string[])

I've been giving an... interesting... task. I've been asked to modify a character array using a pointer. I'm aware that: *char = "something"; //is a literal and cannot be modified. char[] = "...
0
votes
3answers
44 views

Why can't I get the correct value of structure pointer?

I would like to use the ptr[1]->ReadLength in the function, but it always display 0. What the method to solve this problem? Thank you. struct cache_read_block { unsigned short ReadLength; // ...
1
vote
2answers
34 views

How to store multiple strings in a 2-D array? [duplicate]

I want to write a C program that stores a bunch of sentences while it's running and prints them out at the end of the program. Here's what I wrote: #include<string.h> #include<stdio.h> ...
0
votes
2answers
75 views

Reading two dimensional array with dynamic size of integers and output it vertically

I am trying to let user type all integers value in one input like this until EOF: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 then output them vertically: 1 6 11 2 7 12 3 8 13 4 9 14 5 10 15 I have tried ...
1
vote
1answer
43 views

c split an array using multiple delimiters

I'm very new to c and need to split a char* of "/w/x:y////z" by "/" or ":" into an array of char so would get an output of "", "w", "x", "y","", "", "", "", "z", NULL int i; int j; int len = strlen(...
1
vote
1answer
43 views

Dynamically allocated array cannot be used with fscanf?

I am trying to use fscanf to store a file of ints separated by space into an array. This is the code: #include <stdio.h> int main(void) { FILE* fp = fopen("a.txt", "r"); int m = 0, n = ...
-1
votes
0answers
30 views

I am trying to sort out numbers that are bigger then the required limit by including integers and float values. And im not being able to do it

everyone. Hope yall are good and doing good. So I'm trying to run a code that can sort out integers including whole numbers (pointed out by "int") and decimals (pointed out by "float"). So far I'm ...
1
vote
1answer
35 views

How do I scan less chars than defined into an array?

I've encountered a problem while trying to scan chars into an array. This is the scan loop - char letter[6] = {0}; for(int i = 0; i <= 5; i++) { scanf(" %c", &letter[i]); } The desired ...
1
vote
1answer
63 views

Am I passing structures by reference wrong?

#include<stdio.h> struct mystruct{ int age; //age of child int flag; //flag: if 1 then change the age, if 0 then don't }; /////////////////////////...
0
votes
1answer
61 views

C: pointer to array != pointer to &array[0]?

Suppose I have two arrays: uint8_t buf1[10]; uint8_t buf2[20]; I now want to create an array of these arrays, e.g., uint8_t *buffers[] = {buf1, buf2}; When I look at the buffers variable in the ...
0
votes
1answer
33 views

How to split a string and store each character into an array

I'm trying to compare the number of similar characters between 2 string and came across strpbrk() function. But I can't find any method to split my search string into array of character. char search[]...
0
votes
2answers
23 views

(C/C++) fscanf_s Missing Integer Arguments error When Reading in Chars to Array from txt file

First Post, will do my best to follow guidelines and make this a proper setup. If ANYTHING is needed, let me know! The error in VS 2019 is "C6064: Missing integer argument to 'fscanf' that ...
-2
votes
1answer
27 views

How can I write a function whose prototype should be 'void convertstring(char *)' to convert lower case to upper case in C?

This is what I've written #include <stdio.h> void convertstring(char *str[]) { int i; for (i = 0; *str[i] != '\0'; i++) { if (*str[i] >= 'a' && *str[i] <= 'z') ...
-2
votes
0answers
42 views

Im encountering a segmentation error for my array's [on hold]

My code starts with taking 4 inputs (mainly from a text file, but I started with user input as a test): both the x and y axis of a circle on a grid, the radius of said circle and a number of points on ...
0
votes
1answer
38 views

0th value of array being changed after assigning values to separate array in C

I am reading from a file (contents of file labeled in1): 8 0 2 1 4 2 2 3 1 3 2 5 4 6 7 9 2 8 which is passed by command line to my program. (Here is a minimal working version): /* *Run using ...
0
votes
1answer
29 views

array copy in c somehow adds ▄■a even tho debugger doesnt even show it

Ive been writing a code to check a given string (of any length) for given aspects. However I've come across this problem: line_size = getline(&buffer, &buffsize, stdin); int length = ...
-2
votes
1answer
55 views

My Array Function Is Not Returning Variables

The purpose of the program is to take a hex number such as '10' or '01' and convert it to binary to equal 00010000 and 000000001. This is attempted pseudocode of a very complex program: #include &...
1
vote
1answer
31 views

SegFault when setting up 2D character array in C

I am trying to set up a 10x10 grid filled with '$' characters and then print it. char **plot; plot = (char**)calloc(100, sizeof(char)); int i,j; for (i=0; i< 10; i++) { ...
0
votes
2answers
77 views

Why does 32 bit compiler and 64 bit compiler makes such a difference with my code? [duplicate]

Excuse my bad English. I have written down some lines to return max, min, sum of all values, and arrange all values in ascending order when five integers are input. While writing, I mistakenly wrote ...
0
votes
2answers
50 views

C - Writing directly to an array in while loop while receiving data with recv

Here is my code: FILE *responseStorage = fopen("response", "w"); if(responseStorage == NULL){ //error handling } int receivedTotal = 0; while(1){ ssize_t received = recv(sockfd, buf, BUFSIZ,...
0
votes
2answers
28 views

How to assign string of one variable to other variable?

This is my first question on this site. How do i assign string of one variable to other variable. What am i doing wrong here? #include<stdio.h> #include<string.h> main(){ char a[30],b[...
2
votes
3answers
47 views

Synchronization with child signal and parent matches received signals with the file

EDIT: Thanks for the suggestions given so far. I changed the program and now the parent handles some of the signals, but it looks like it doesn't handle all of them. New code and results are posted ...
-1
votes
5answers
52 views

C language pointers and arrays

#include <stdio.h> int main() { char c[]="PRODUCTION 2019"; char *p=c; printf("%s",p+p[3]-p[5]); return 0; } I don't understand how the output is RODUCTION 2019 . Can someone ...
3
votes
2answers
80 views

C/C++ DWORD to BYTE and BYTE to DWORD conversion in Three-Dimensional Array

I am struggling to understand if I am doing this the correct way and if this is the (only) best solution. The project I am working on is using a Three-Dimensional Array to hold and use lots of data. ...
0
votes
1answer
43 views

Returning a pointer to a char array inside a struct in C?

I have the following struct in the header file: static FILINFO fno; Which looks like so: typedef struct { DWORD fsize; /* File size */ WORD fdate; /* Last modified date */ WORD ...
-3
votes
1answer
31 views

Can someone explain to me how does this code work?

#include <stdio.h> int main() { int array[101]={0},i=0,n; printf("Enter numbers: \n"); for (int i=0; i<1000 ;i++){ do { scanf("%d",&n); if ((n<0 |...
0
votes
0answers
40 views

C store user string in an array to access

Hey guys I am trying to create a function that takes my cmdstring and stores each value into an array. Right now my program takes user input and then everything seperated by a space will be printed ...
0
votes
1answer
74 views

Face detector program in C via arrays

So I need to make a "face detector" program in C. Basically I need to input the number of "face detections", resolution height and width (max 120), and the coordinates of the "face". Then the input is ...
-2
votes
1answer
51 views

Best way to split the array into smaller chunks - C programming

What would be the best way to split an array of let say size 2000 into chunks of 250 elements. array[2000] --> split into chunks of 250 elements, 8 sub arrays. Thanks.
1
vote
2answers
62 views

Handling arrays in C

I'm just a beginner with C language. I want to determine elements of array, but it failed. I'd like to insert index(row=x, column=y). Is this possible? Here's my code. #include <stdio.h> #...
-10
votes
0answers
48 views

Why this code snippet fails to reverse an array in c [on hold]

I'm new to programming. I'm writing a code to reverse an array in c. Although there are many methods to accomplish that, I'm curious that why can't I print the elements of an array from the highest ...
-4
votes
2answers
53 views

C Programming: Why do two of my variables share the same address? [on hold]

Background: I'm trying to get 2 arrays going with separate variables, however both the A[0] and E[2] are coming up with the same address. Am I missing something? Is there a way to fix this? Thanks in ...
0
votes
1answer
28 views

How Do I Store Contents of a File into an Array (C)

FILE *pFile; pFile = fopen("address01", "r"); int yup[8]; int* array[7]; for (int i = 0;i < 7; i++) { while (!feof(pFile)) { fgets(yup, 8, pFile); puts(yup); //It DOES ...
0
votes
2answers
66 views

Syntax for returning array pointers in C

EDIT: the correct syntax for declaring a function with the return type of array pointer in the example I wrote further below in my code example section should be as follows: int (*my_function(void))[...
1
vote
1answer
43 views

How do I use fork to make linear searching more efficient on an unsorted array?

I am trying to implement a simple iterative search function with fork() to make linear search on an unsorted array (variable size) more efficient. If the array is small enough, say less than size 1,...
0
votes
3answers
59 views

How can I delete the first entries from a string

This is my task: Write a program that reads a string w of maximum length m = 100 and two indices a; b element of [1; 100], with a smaller or equal than b from the keyboard. Then, the substring ...
4
votes
2answers
88 views

Is it undefined behavior to get the address of an array element that is out of bounds?

Let's say we allocate a byte array of 10 elements. Accessing any element within bounds is defined. I understand that reading and writing elements out of bounds is undefined behavior. Is it undefined ...
0
votes
2answers
29 views

Printing the minimum and maximum of an array [duplicate]

I'm having a problem with finding the minimum and maximum value in an array. #include <stdio.h> int maximum(int array[], int n); int minimum(int array[], int n); int main() { int array[...
-2
votes
1answer
44 views

I have trouble with the following code with different variable types and pointers for finding Bessel functions

This assignment is one of my labs and it wants us to find the value of the 1st order Bessel function according to the input-ed user value. So long, my mindset is: first I will ask the user for input, ...