Questions tagged [array]
The array tag has no usage guidance.
104
questions
0
votes
1
answer
19
views
substitution question segmentation fault issue
I am doing the substitution question and I keep running into this segmentation fault issue but i do not understand what exactly is causing the memory access issue. once j=4, the memory fails to be ...
0
votes
1
answer
44
views
Use of undeclared identifier 'num'
I dont really know where im wrong. it gives me "use of undeclared identifier 'num'" i allready tried to solve it but i have no clue of what is going on
#include <stdio.h>
int maxc = 0,...
0
votes
1
answer
21
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?
0
votes
3
answers
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
1
answer
44
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
1
answer
22
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
2
answers
224
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
1
answer
31
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
1
answer
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
1
answer
18
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
1
answer
52
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
1
answer
462
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
1
answer
35
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
1
answer
76
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
1
answer
24
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
1
answer
69
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
1
answer
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
1
answer
274
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
1
answer
45
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
1
answer
41
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
1
answer
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
2
answers
138
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
1
answer
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
1
answer
76
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
1
answer
43
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
1
answer
325
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 ...
0
votes
1
answer
99
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
1
answer
24
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 <...
1
vote
1
answer
127
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
1
answer
377
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
1
answer
499
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
1
answer
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
1
answer
88
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
1
answer
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
1
answer
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
1
answer
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
3
answers
203
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
1
answer
26
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
2
answers
3k
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
1
answer
59
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
1
answer
150
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
1
answer
427
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
1
answer
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
1
answer
51
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
1
answer
998
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 ...
0
votes
1
answer
64
views
handlign multidimesional arrays as function arguments and return values
So I stuck at the pset3, at the place where you need to implement game of fifteen. How can I pass multidimensional array as an function argument? And how can I return multdimesional array as a ...
0
votes
1
answer
165
views
How could you create a dynamic array of strings in C?[Beginner]
How do you create a dynamic array of strings? Like if I had this code
printf("What are the names of your pets?");
what piece of code would I write to get multiple string answers from the user?
(I'm ...
0
votes
1
answer
1k
views
trail of strange characters after printing character array
I wrote my vigenere cipher program and everything works fine, but when I run check50 I get the following error:(p is the plaintext string)
char c[strlen(p)];
for(int i = 0, j = 0, l = strlen(p), n = ...
0
votes
1
answer
230
views
How to use fseek along side arrays? Pset4 recover
I'm re-wrote this code and did not get any output or error. Tried valgrind and nothing was leaked.
I suspect it's either:
1) my fseek is not moving my cursor in inpt 'card.raw'
2) and/or.. because ...
0
votes
2
answers
94
views
Pset 2 - Vigenere Checking Command Line Input
I am working on the Vigenere portion of the pset and appear to have it totally working, yet when I ran the checker I realized that I had not created a test for non-alphabet characters in the command ...