Questions tagged [array]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
3answers
19 views

Error retrieving return values ​from a function

I am currently studying coding in C language and I have doubts about the return of functions, what I am trying to do is the following: Call the number () function and pass 3 values ​​of the integer ...
0
votes
1answer
17 views

Why is an Array longer then the input?

why we can access more information than the lenght of the array? I thought that after the Null (0) the array ends. Why we can access position 40?
18
votes
2answers
50k views

Difference between char and char* in c

suppose we declare two variable char s[]= "hello" char* p = "hello". what is the difference between these two?
0
votes
1answer
43 views

Why is this generating wrong output and Runtime - out of bound error?

I have a program below, which gets some random numbers from users and then multiply every second to the last digit by 2, stores it into an array and print out the value of each array index. It seems ...
0
votes
1answer
43 views

2D array of given size

I want to create a 2D array of ints, where the array's dimension is given at run time (not compile time). So far, I have been using: int **ptr = malloc(m * sizeof(int*)); for (size_t i = 0; i < m;...
0
votes
1answer
59 views

How to get maximum element of array from index a to index b?

I keep getting the error format specifies type 'int' but the argument has type 'int ()(int , int, int)'. printf("%d", get_max); I'm new to pointers and coding C in general and still haven't ...
0
votes
1answer
23 views

Why am I able to insert an element into a hash tree via Main() but not via a function call?

I'm fairly certain this has something to do with pointers and the function using copies instead, but I'm not sure how...because I've inserted the pointer as a parameter for create(); #include <...
0
votes
1answer
303 views

CS50 PSET2 code will not compile

I would appreciate any help that could be given with my code below (+ error codes below that): My code will not compile and the primary error apparently is an "undeclared identifier" refering to ...
0
votes
2answers
1k views

Why is my array of RGBTriple not working?

I know there are a lot of questions surrounding this topic. Read 'em, still having trouble. The common suggestion here for declaring an array of RGBTriples is something like the following: ...
0
votes
1answer
243 views

I've use array pointer method in pset2 (initials.c) but it return "Segmentation Fault (Core Dump) Why?

I'm working on pset2 using array pointer method, but unfortunately, the program return "Segmentation Fault (Core Dump)" I've post a picture of my code below.Can I use this method? or I have to use if ...
0
votes
1answer
1k views

pset8 import: Problems with the delimiter in fgetcsv

*EDIT I seem to be having some trouble with the fgetcsv function. In my code I am trying to create a single row array with each tab separated value as a separate element in the array. Instead of ...
0
votes
1answer
23 views

When I multiply my array by 2 it doesn't give expected value

Also, please when I try to add "firstnumsum", it doesn't give expected value and I don't know what to do. #include <cs50.h> #include <stdio.h> #include <string.h> #include &...
0
votes
1answer
48 views

Readability compiling issue

Readability (Problem Set 2) #include <stdio.h> #include <cs50.h> #include <string.h> #include <ctype.h> #include <math.h> // Letters detects letters // Words detects ...
0
votes
1answer
30 views

Getting different outputs when I use debug50 and when I run the program

When I use debug50 on this program I get 26 as the value of 'a' but when I run it I get random large values of 'a'. #include <cs50.h> #include <stdio.h> #include <string.h> #include &...
0
votes
1answer
131 views

cs50 array initializer must be an initializer list

i have started coding in c but i keep getting errors i don,t know how to solve maybe it is because i am used to coding in php language but i hope anybody can help me #include <stdio.h> #include &...
0
votes
1answer
36 views

Help with Either Command Line Argument or Arrays for Problem set 2 Caesar

I am on Problem Set 2: Caesar. Right now I'm trying to write code that first checks if the second command line argument is a int and if it does prints the integer. I got my program to compile after ...
0
votes
2answers
48 views

Caesar : Extra random characters at the end of a char ciphertext array

I'm having a problem with an output. Sometimes output adds an extra characters, different each time the code runs. For example, when I use key "1" and write "a", it displays "...
0
votes
1answer
25 views

Having Trouble using StrCpy with Command Line argument for Problem Set 2 Caesar. Trouble with Array

Hello I'm still fairly raw at this coding thing so i'm sure im making rookie mistakes. I'm doing Problem Set 2 caesar and I've hit a wall and haven't been able to move forward. What I have been trying ...
0
votes
1answer
14 views

When I'm creating array

This has me confused. In the following code, I create an array of characters initialized at size 7. The array needs to store at least 6 characters, so I've made it large enough to do that (I think?). ...
0
votes
1answer
15 views

How can i arrange the output in decending order In this program? [closed]

#include <stdio.h> int main() { int n,i; printf("Enter a number: "); scanf("%d",&n); for (i=0; i<=n; ++i) { if (i%(7*13*19)==0) { ...
0
votes
1answer
14 views

PSet 5 Speller - Expected Identifier

Been stuck on Speller for 2 days and could really please use some help. My initial idea is just to create an array of linked lists with 26 buckets (N = 26) and very simply hash the words by only the ...
0
votes
1answer
30 views

Having trouble identifying non-decimal digit in Caesar PSET 2

I'm working on Caesar from Problem Set 2. I have done the first step to check for a single command line argument, but I'm stuck on how to check the argument to see if any characters are non - decimal ...
0
votes
1answer
34 views

Week 2 passing array example problem?

Hi, I have problem understanding the concept of 'passing an array by reference instead of value' and I cant understand this example. Can anyone explain to me why does it take 10, 22 as final answer?
0
votes
0answers
54 views

Encrypt plaintext in substution.c

Here is my encryption of plaintext after validation the key. //Encrypt Code string plaintext = get_string("plaintext: "); // int array[26] = {0}; string encText = plaintext; //converts user ...
0
votes
1answer
57 views

My code for Caesar gets segmentation error when executed, but in debugger it works fine

I'm getting a segmentation error as soon as I execute this program. I've run it through the debugger and it works fine and outputs the correct ciphertext. There's gotta be something going on in the ...
0
votes
1answer
247 views

check50 claiming pairs are sorted incorrectly

On Problem Set 3, check50 has flagged my program as not having sorted the pairs correctly. However, the pairs array appears to be sorted in every case I've tried. I used insertion sort and had ...
0
votes
1answer
32 views

In pset2, Vigenere, I made and used an array that I would like for it to be explained

I’ve successfully solved Caesar and Vigenere pset but made and used an array that I stumbled upon through trial and error but don’t exactly know why and how it worked. I’m hoping someone could clarify ...
0
votes
1answer
26 views

PSet2 why isn't this providing output

This segment of code only prints out blank lines. Key is the correct integer, but I must be handling the array of characters incorrectly. Thoughts? int key = atoi(argv[1]); for (int i = 0, c = ...
0
votes
2answers
126 views

Pset3 Resize Array not storing data properly

I'm not sure where the issue is here, but from the looks of debug I only store anything in my horizontal array (line) once despite seeing the debugger hitting that section of code properly. I assume I ...
0
votes
1answer
56 views

Pset2 Vigenere, array with garbage

I am getting some garbage values when declaring my array. I kinda understand that when declaring without initializing it provides garbage values, but I don't understand why the array is larger than ...
0
votes
1answer
74 views

Caesar not getting output

I'm stuck troubleshooting what is wrong with my code. It prompts for plaintext correctly, but when entered returns a blank "ciphertext: ". # include <stdio.h> # include <cs50.h> # include ...
0
votes
1answer
27 views

Why string variable has no square bracket?

Though it's said that string is an array of characters why string variable does not have square brackets on the immediate right? In CS50 we call string as string s why not as string[]? then how can ...
1
vote
1answer
235 views

array size in C

I have question regarding array size declaration in C. I see that if I declare an array in the main function without specifying its size like int arr[]; arr[0] = 7; arr[1]= 8; it shows an error ...
2
votes
2answers
126 views

how effective would it have been to use an array for the dictionary?

I just completed pset5 using a trie, but I'm curious about other methods. How effective would it have been to load the dictionary into an array and then use a binary search function to locate words ...
1
vote
1answer
120 views

Pset2: Copying string contents

I just can't seem to get this right. The example in the week 2 short Arrays is as follows: int foo[5]{1,2,3,4,5}; int bar[5] for(j=0;j<5;j++) { bar[j]=foo[j]; } This does not seem to work with ...
0
votes
1answer
315 views

Problem accessing the last element of the array

I've decided to implement the load function using trie, which I've defined as typdef struct trie { struct trie letters[27]; bool isWord; }trie; then later, when I try to ...
0
votes
1answer
34 views

Pset4 - Array declaration- Heap

In shorts of Pset4 it was mentioned, that pointers are created in heap. Does it mean, that all arrays are stored in heap?
0
votes
1answer
87 views

Pset5 Dictionary C Struct Array Call In Load Function Issue

I've defined the struct as following: // Node struct typedef struct node { // Node value char word[LENGTH + 1]; // Node Pointer to next value/node struct node* ...
0
votes
1answer
2k views

I'm getting a runtime error on an array and I'm not sure why:

The following code Compiled but gave me an error (credit.c:21:7: runtime error: index 15 out of bounds for type 'int [15]') on the last line included while running: int m; int r; int counter; int ...
1
vote
1answer
36 views

Passing SQL values into arrays

I'm designing a budgeting website for the final project. One of the features that I want to implement is to be able to track how much money you've spent for each item category. The SQL command that I'...
0
votes
1answer
57 views

pset vigenere skipped over if statement

for (int i = 0, j = strlen(s), k = 0; i < j; i++, k++) { if (isalpha(s[i])) { if (isupper(s[i])) { if (argv[1][k] ...
0
votes
3answers
202 views

pset2 vigenere shifting characters by the same

for (int i = 0, j = strlen(s), k = 0; i < j; i++, k++) { if (isalpha(s[i])) { if (isupper(s[i])) { if (argv[1][k] != '\0') { printf("%...
0
votes
2answers
2k views

pset2 caesar converting from ascii to alphabetical

#include <stdio.h> #include <cs50.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, string argv[]) { if (argc == 2) { int ...
0
votes
1answer
25 views

pset7: why do we need [0] in from of list? (e.g. someData[0]['dic']?)

Just completed pset7, gosh it was a long one, took a month! Am curious as to why we need to have a [0] in front of the list to get the "pure" data? For instance, when we get back a list while ...
0
votes
1answer
57 views

Declaring an array of structure pointers

How to declare an array of structure pointers? I need to create a collection of linked list. Is it same as declaring ordinary arrays? If
0
votes
1answer
127 views

Array declaration need explicit size?

Can I create an array with no specific size or intializer? I'm trying to make an array of 26 english character but I don't want to just declare 26 slots right from the beginning int main(void) { ...
1
vote
1answer
426 views

Pset4 Resize.c Array Overstepping

I have been stuck on resize for a while. I am currently struggling on the vertical portion of resize. I am using the "rewrite" method as explained in the problem spec. My program does resize an image ...
0
votes
1answer
1k views

Pset4 - Recover (usage of sprintf)

When I am working on Pset4 - Recover, I realize I do not understand the concept of array and pointer. Although I finally worked it out, I would be very grateful if you guys can explain the following: ...
0
votes
1answer
50 views

Game of Fifteen - Move Function - getting wrong coordinates?

I have been working on the game of fifteen problem and seem to be having an issue. I keep getting an "Illegal Move" when it is a legal move. I think I have found part of the issue and I would just ...
0
votes
1answer
959 views

Why this code leads to segmentation fault?

1) In CS50 ide, it does not even compile giving error: format specifies type 'int *' but the argument has type 'int' [-Werror,-Wformat] scanf (" %d", array[n]); 2) In codeblocks, it runs ...