Tagged Questions
1
vote
1answer
19 views
C- to check if a char in a string belongs in an array
Basically what I'm trying to do is that when a user inputs a string, my code will check the characters one by one and see if they belong to an array or not.
For instance i have an array:
char ...
0
votes
1answer
38 views
Can't assign string to pointer inside struct
Here is a piece of my code, I tried to make it simpler I am trying to assign a string to a pointer inside a struct that is inside an array, also I would like to initialize pointers to NULL so I can ...
5
votes
4answers
107 views
Are two dimensional arrays in C required to make all elements contiguous?
I heard from a friend that two dimensional arrays in C are only supported syntactically.
He told me to better use float arr[M * N] instead of float[M][N] because C compilers like the gcc can't ...
0
votes
7answers
58 views
typedef required in struct declaration
I'm trying to create an array of struct elements, as shown below:
#include <stdio.h>
#include <stdlib.h>
struct termstr{
double coeff;
double exp;
};
int main(){
termstr* lptr = ...
0
votes
6answers
52 views
Expand array of structs using realloc
I am passing a struct through a function like so...
expandArrayofStructs(Container *container, int n)
This container is one struct and inside of that struct is an array of another type of struct ...
0
votes
1answer
32 views
Insert string into array - PAWN script
I am trying to cut down my file lines by having one variable to insert into several arrays. So I'd like to have a string, or an array variable, such as the following:
new combomeals[] = {
...
-1
votes
2answers
123 views
Navigating arrays in C (performance)? [closed]
Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?
How does the compiler treat both approaches?
-5
votes
1answer
64 views
Questions about pointers and arrays in C [closed]
I have a question about this simple program in C to practice with pointers and arrays.
Code:
#include <stdio.h>
fun(int *p, int *v) {
*p++;
*(v+2) = p[3];
*v++ = p[0];
v[0] = ...
0
votes
1answer
47 views
what will happen if we copy more data from source to destination using memcpy?
I have the following code:
int dst[5];
int src[100];
// assign value to array src
memcpy(&dst[0], &src[0], sizeof(int) * 100);
what will happen in this case? will only the first 5 elements ...
1
vote
1answer
55 views
how the following memcpy is beyond array in C?
I have the following code:
#define NUM_STUDENTS 20
#define TIME_STUDENTS 10
typedef struct
{
int name;
int age;
} Student;
typedef struct
{
int number;
int post;
} Contact;
typedef ...
-8
votes
3answers
50 views
Access element of array of pointer of structure
I want to access the element of array of pointer to structure but i have no idea how to access it.
#include<stdio.h>
int main()
{
struct hash
{
int pages;
int price;
};
struct hash ...
-2
votes
2answers
65 views
cannot convert parameter 1 from 'char [20][20]' to 'char ** '?
My Code is below:
#include <stdio.h>
void print_pointer(char **str);
void print_array(char *str[20]);
void print_array2(char str[20][20]);
void print_array3(char str[][20]);
int main(int ...
1
vote
2answers
44 views
iterate through array of strings with zero at the end
I have a char* array that looks like this:
{"12", "34", "", 0}
I'm passing it to a function, so it decays to a pointer. So I have a function that takes in a char**, and within the function I want ...
1
vote
3answers
36 views
Expand an Array of structs to a larger size dynamically
I have a dilemma where I have a struct which contains an array of structs...
typedef struct Container{
struct Inner *F;
int length;
} Memo;
typedef struct Inner{
int *digits;
int ...
0
votes
2answers
42 views
trouble with fopen and sprintf
I understand the syntax for fopen in C is
fp = fopen ("file2.txt", "r");
My question is, if I wanted a txt file path in a char string that I made to be opened, could I do
char str[100];
FILE *fp;
...
0
votes
2answers
68 views
Passing an array to a function as array vs as a pointer
I am a newbie to C and I am looking the ways to pass an array to a function and access the elements.
I find that there are 3 ways to do that.
pass in an array, and the function specific the ...
1
vote
2answers
83 views
Putting Struct information into one big array
I am looking for a way to put an entire structs information into an array. The reason for this is that a function I am working with requires an array of information to read from. Instead of calling ...
-4
votes
1answer
106 views
Why a[v] = v[a]? [duplicate]
v it's an array of ints and a it's an int:
#include <iostream>
using namespace std;
int main() {
int v[10], a;
cout << v[a] << endl;
cout << a[v] << endl;
return 0;
}
...
2
votes
2answers
37 views
Warnings when creating a singly linked list with arrays
#include <stdio.h>
typedef struct
{
int data;
struct node *next;
}node;
void print(node *head)
{
node *tmp = head;
while (tmp)
{
printf ("%d ", tmp->data);
tmp = ...
1
vote
1answer
38 views
creating 4D lookup table
I need to create fast 4D lookup table according to the following:
1- it will receive 4 input variables (u,v,i,j) each one range from 0 to 15
2- the lookup table returns a precalculated value of 8 bit
...
-3
votes
3answers
83 views
array not being read properly
I have a 2D array. I am iterating all the 8 rows and 10 columns and reading the values using a for loop. Here is the our array and the output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 ...
0
votes
3answers
52 views
int array inside a struct inside a struct
I am trying to achieve this... A single container which holds an array of structs and inside each of these structs are a single int array which represents an integer like so... 12,345 would be inside ...
0
votes
3answers
39 views
Incorrect output in an array inside a struct
I have a struct with an int array inside that I'm passing to a function for the array to be initialized
array struct like so..
typedef struct Container{
struct intArray *P;
int length;
} ...
1
vote
1answer
53 views
Pointer to statically defined two-dimensional array
Code (compiled using gcc -std=c99) ...
#include <stdio.h>
#include <stdlib.h>
typedef int mytype[8][8];
int main(void)
{
mytype CB;
for (int r=0; r<8; r++) {
for (int ...
-1
votes
2answers
97 views
Strange behaviour when casting array char to array short
I have 2 array: the first one is 8 unsigned char, and the second one is 4 unsigned short, for some algorithm compatibility issue i need to use the short array with the values of the char array, to do ...
-5
votes
2answers
63 views
error expected ';' before ')' in simple array code [closed]
im trying to learn c code on my own. this was a exercise i found on the book. But i can't seem to solve it
for (i=1;i<=3,i++)
i think this code is wrong can someone confirm it
i tried ...
0
votes
1answer
53 views
int Array in a Array of Structs in a Struct
I hope I don't get hammered on this site. I am a novice programmer having much difficulty with this concept. I have been tasked with memoizing the fibonacci sequence. A concept which I think I have a ...
0
votes
2answers
32 views
Contiguous mutable ordered list
This may or may not exist, but I'm looking for a way of storing a sorted list of integers that's contiguous in memory, reasonably compact, and allows for O(log n) amortized inserts and deletes. The ...
1
vote
1answer
27 views
3D Array of _unequal numbers_ of strings
I realise this has probably been done before but searching has turned up blank for this specific wrinkle.
If we want to define an array containing some strings, we can do:
char *strings[] = ...
0
votes
3answers
86 views
How do I extract operators from a char array?
I have two arrays, one of them has ints, and the other has chars of operators. So, suppose I have the following arrays: [12, 3] and ['+']. I want to transform this into the expression 12 + 3, which ...