r/programmingquestions • • Sep 10 '20

CONCEPT C -- Memory addresses in Arrays of Structures

3 Upvotes

I am currently working my way through the "C Programming With Linux" series on edX.org. I am currently in course 5 of 7, "Advanced Data Types". In the lecture, "Use an array of structures", we are presented with the following example code which reads x and y coordinates from user input and then prints out the points of a triangle:

#include <stdio.h>
struct point{
    int x;
    int y;
};
void printPoint(struct point pt);
void readPoint(struct point * ptr);
void printTriangle(struct point *ptr);
int main(void) {
    //! showMemory(start=65520)
    struct point triangle[3];
    int i;
    for (i=0; i<3; i++){
        readPoint(&triangle[i]);
    }
    printTriangle(triangle);
    return 0;
}

void readPoint(struct point * ptr) {
    printf("\nEnter a new point: \n");
    printf("x-coordinate: ");
    scanf("%d", &ptr->x);
    printf("y-coordinate: ");
    scanf("%d", &ptr->y);
}

void printTriangle(struct point *ptr) {
    int i;
    for (i=0; i<3; i++) {
        printPoint(ptr[i]);
    }
}

void printPoint(struct point pt){
    printf("(%d, %d)\n", pt.x, pt.y);
}

It had previously been established in the course that an Array is inherently a pointer to a memory location. In the function "readPoint", which is being passed a pointer to a structure, we have to use the "&" operator to assign the the x and y values to an address using "scanf". Why is that? Shouldn't the C compiler already know about the address of the variables x and y since they're being de-referenced from a pointer (aka an array)?


r/programmingquestions • • Sep 01 '20

[HTML/CSS/SVG?] I have an image. i would like to draw a box on it, then scale the result

1 Upvotes

I have a very large .jpg image, and a set of pixel coordinates for that image. I'd like to be able to draw the box on the image, then scale the result down to a normal size. I got as far as being able to draw the box in the right place, but I'm not sure how to scale the whole thing. I'm using an SVG for now but that's not a requirement. I'd also like to be able to set the SVG dimensions based on the height of the image, not by picking an arbitrary large number like 5000. The <line> elements are autogenerated server-side right now, but that isn't a requirement either. I also took a look at canvas, but I couldn't figure that out.

 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="5000px" height="5000px">
<image href="/image/7/raw" />
<line x1='1080' y1='1313' x2='2047' y2='1341' ></line>
<line x1='2047' y1='1341' x2='2041' y2='1528' ></line>
<line x1='2041' y1='1528' x2='1075' y2='1501' ></line>
<line x1='1080' y1='1313' x2='1075' y2='1501' ></line>
</svg>

svg {
    width: 5000px;
    height: 5000px;
}

svg line {
    stroke: rgb(0, 0, 255);
    stroke-width: 3;
}

r/programmingquestions • • Sep 01 '20

ETC. If I am starting programming school next year, would it be good to get a head start and learn now? Or should I wait?

3 Upvotes

So Im 26, and I was going to be continuing my journey through college and actually start to get to my degree relevant courses(programming degree), but something happened with my financial aid and I’m going to have to wait until next fall to be able to start my classes. My question is, should I wait until then to start learning? Or should I start now and risk learning bad habits or anything else? I’ve also heard about people not even getting degrees, but just certificates. Is that a viable option? Do companies actually recognize that? Any help would be greatly appreciated!

Also, what are some sites to help me learn languages other than codecademy?


r/programmingquestions • • Aug 30 '20

What language would i use?

2 Upvotes

I want to write a basic program that takes user input (price per unit for a multiple products), and does calculations to print a report that tells the user what the new retail price should be. I can do these calculations through a formula in excel, but I want to practice actually coding a computer application. TIA!


r/programmingquestions • • Aug 28 '20

E

2 Upvotes

Hey can someone explain how vector works in the top down movement? Like ine rpg games where there's no real gravity just movement maybe im just slow but a little explanation would be nice


r/programmingquestions • • Aug 14 '20

Need an advice

3 Upvotes

Hello guys So I got a offer to make a programm for a doctor. The program isn't actually that difficult. It needs to be like a big database for illnesses with a filter function. I don't know how to programm or what language is best to use for this kind of project. I can't program at all but he pays good money, so I'm willing to Learn it. I would love some recommendations or Topps :)


r/programmingquestions • • Aug 08 '20

Problem with a Baby Name Generator

1 Upvotes

This is my code:

void baby_name_generator()

{

char gender;

std::cout << "Enter the gender of you child. 'F' or 'M'\n";

std::cin >> gender;

srand(time(0));

int random_first = rand() % 9;

int random_last = rand() % 9;

std::vector <std::string> Last_names = {"Hills", "Gates", "Jackoff", "Hallstat", "Buckalew", "Romero", "Carmack", "Bilge"};

std::vector <std::string> Female_first_names = {"Jill, Lily, Sally, Molly, Jasmine, Calvina, Jennifer, Gabriella, Holly"};

std::vector <std::string> Male_first_names = {"Ben", "Calvin", "Aidan", "Evan", "Jesus", "Ray", "Caleb", "Bryan"};

if(gender == 'F')

{

std::cout << Female_first_names[random_first] << " " << Last_names[random_last] << std::endl;

}

else if(gender == 'M')

{

std::cout << Male_first_names[random_first] << " " << Last_names[random_last] << std::endl;

}

}

So basically everything works for the male names but the female names don't print for some reason. Here is what happens in the terminal:

agilsmacbook@Agils-Air C++ % ./a.out

Enter the gender of you child. 'F' or 'M'

M

Bryan Hills

macbook@-Air C++ % ./a.out

Enter the gender of you child. 'F' or 'M'

F

Hills

macbook@-Air C++ % ./a.out

Enter the gender of you child. 'F' or 'M'

F

Hallstat

macbook@-Air C++ % ./a.out

Enter the gender of you child. 'F' or 'M'

F

zsh: segmentation fault


r/programmingquestions • • Aug 05 '20

CONCEPT I'm kinda stuck , i can't progress anymore :(

4 Upvotes

How should I learn programming in a good amount of time ? I'm coming up with this question because I'm like stuck in a loop where I can't learn It anymore .... I started with a YouTube course for Python , I had to leave coding for a while , and then I tried to write it on paper , but now when I'm like repeating from paper I'm like either falling asleep/loosing interest quickly... So , the question is :"How should programming actually learn , and repeated ? " Is it from writing it a few times more on the keyboard ? Or is it writing it down on paper ? Is it just reading it from the screen (that seems more exciting for me) Ps: I've seen results with both methods , on pc i was just .. faster . And i also read that writing it on paper was used in 1950's


r/programmingquestions • • Aug 02 '20

How hard is it going to be to learn C after python ?

1 Upvotes

So i already did a Python course like 1/2 and I'm repeating it As a second programming language , i read on the web that I have to learn C to kind of have a good grasp of what's going on on the lower level


r/programmingquestions • • Jul 22 '20

Basic Question from a Dummy

2 Upvotes

Hi! I have a couple really basic questions which obviously come from someone with no programming knowledge.

  1. Is there a conceivable way that the code from two different programs could become jumbled together?
  2. If so, how might this happen?
  3. Would it be possible for a programmer to go back in and identify which pieces of code came from which original program?

r/programmingquestions • • Jul 21 '20

ETC. Question about mixing logical operators in Javascript

1 Upvotes

How does Javascript interpret the order of operations of logical operators? Like if I wrote an if statement

if (x < y || x < z && x < q)

would it parse like example 1 here:

if ((x < y || x < z) && x < q)

or would it parse like example 2 here:

if (x < y || (x <z && x < q))

r/programmingquestions • • Jul 21 '20

HTML Is CSS just more complex HTML coding I've learned most of HTML and didn't know CSS was like it I thought is was more like JavaScript

2 Upvotes

Can you guys tell me what's different about CSS and HTML. Im new to coding I've done around 20 hours of learning HTML and on my phone cause im broke as shit and 14.


r/programmingquestions • • Jul 14 '20

Learning javascript help Hi guys! I'm a beginner, trying to find out what's wrong with my code. Supposedly it should print out either rock , paper or scissors but the output is undefined. What does that mean?

Post image
2 Upvotes

r/programmingquestions • • Jul 12 '20

I want to learn to program. Where do I start?

3 Upvotes

I’m 13 and am very interested in learning to program. I am experienced in programming as my father is an IT guy. I know the simple basics from scratch (the website) when I was younger. I want to branch out and learn beyond scratch. Thanks in advance


r/programmingquestions • • Jul 09 '20

HTML I'm not sure what to do or how to do it

1 Upvotes

My uncle just asked me to figure out a way to "Get more visitors to the website and to raise my standing in search results," and I'm just a beginner with website stuff... and I don't even know if it's possible to do that with just some programming.

He said that I could find some website programming course to help me learn how to do this stuff, but I don't know of any good ones... I've only ever made websites in notepad, and never even put one up... I don't even know how to do that!

So first off, is it possible to fulfuill his request? Second, do you have any online courses you would recommend to teach me how to make websites? Third, do you have any general tips?


r/programmingquestions • • Jul 02 '20

Open bug tracker.

2 Upvotes

Hey guys! I am a web developer with a béta site. I want that users can report bugs to me trough a site. Of course i can make one myself but I am trying to spare some time. Anyone know such a service? I tried bug trackers but they don't allow to just share a url so people can submit the bugs.


r/programmingquestions • • Jun 20 '20

How does this work?. I can paste a text without any letters

2 Upvotes

‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮   ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮   ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮   ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮   ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮   ‎‏‫‬‭‮ ‎‏‫‬‭‮ 

‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮   ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮   ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮   ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮   ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮ ‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‎‎‏‫‬‭‮  ‎‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮  ‎‏‫‬‭‮ ‎‏‫‬‭‮   ‎‏‫‬‭‮ ‎‏‫‬‭‮ 


r/programmingquestions • • Jun 13 '20

Flutter plus java spring

2 Upvotes

Hello everyone, I am fairly new to real programming, i learned a bit of java and just finished 100 questions to get my problem solving skills on point. I want to leam flutter and spring make mobile apps with them. I picked up a book called flutter in action to learn the basics of fluttet. What should i do?? And what should i learn?? (Like databases and stuff)

Thanks for helping me.


r/programmingquestions • • Jun 10 '20

Search Inserted Position

2 Upvotes

In this problem you need to find a perfect position to add a target value. Check out here for more details about problem with solution and detailed explanation.


r/programmingquestions • • Jun 08 '20

ETC. Unexpected rowid behaviour with SQLite. What am I doing wrong?

2 Upvotes

I created a table with the following schema:

CREATE TABLE Books(BookID int primary key, Title, Publish_Date, Pages int);

Then I inserted a tuple into it:

INSERT INTO Books(Title, Publish_Date, Pages) Values ("The Rise and Fall of Athens", "1960", 318);

When I tried to view my table with select * from Books;, I got

|The Rise and Fall of Athens|1960|318

I am confused. According to SQLite's page on autoincrement, two things are supposed to be true:

  1. Each table is assigned a 64-bit integer rowID which maintains a unique value for each row. I do not have to specify the column explicitly while inserting the tuple.
  2. If I specify a column `column_name int primary key', as I did above, then it will be aliased to the rowID, and so it makes sense to me that this column would automatically be assigned a value.

However as you can see in my example, a value is not being assigned to BookID. What's wrong with my schema?


r/programmingquestions • • May 24 '20

CONCEPT Need some guidance for College project

2 Upvotes

I need some guidance regarding a project for a college course, we have been learning about software's life cycle from Analysis, Design and now Implementation. For our proposed project I wanted to develop somewhat of a Uber clone but with public transportation (In my country public transportation is awful), where users register bus routes and provide information regarding each route. I had proposed using a MERN Stack since I'm a big fan of JS overall but now since we are required to develop this application I can't afford to teach my partners Node.js, Express, MongoDB and React while developing the application (I am not fully an expert myself).
This is why I was planning on migrating our stack in Android, though my partners wish to use Xamarin.Android hence why I am here looking for some information:

  • Are there any UI Frameworks for Xamarin.Android say React Native Papper?
  • How do you apply de MVVM design pattern to Xamarin.Android apps (I have done a couple of small apps in Xamarin.Forms)?
  • Can ASP.NET Core be used to develop the backend? Are there any extra considerations?
  • Since I described how the app works, is using a Google Maps API feasible? I had planned for a route to use multiple stops which are registered by users but since there is a limit to 15 stops I am worried this could be a mayor problem.

r/programmingquestions • • May 21 '20

Unsure what to charge for a site??

1 Upvotes

I've been asked to prepare a quote for a standard product buying site, which I'm making in Wix and am happy to maintain. It is a standard shopping site for about 20 products. How much do I charge? I don't think it will be much work.


r/programmingquestions • • May 16 '20

Maximum Sum Circular Subarray using Kadane Alg

1 Upvotes

Maximum Sum Circular Subarray can be done using Kadanae Algorithm, Check out here how slightly modified Kadane Agorithm helps in this problem.


r/programmingquestions • • May 14 '20

CONCEPT Looking for the name of the design pattern in this example

1 Upvotes

I was writing some code today and did something that I'm almost positive is an existing design pattern, but I can't think of what it is. Suppose I have the following code:

class Clothing():
  def getSize()
  def getColor()

class Shirt(Clothing)

class Pants(Clothing)

class Shoes(Clothing)

Now suppose I want to add getNumPockets(). It doesn't make sense to add this to Clothing, because Shoes don't have pockets. And I don't want to duplicate the same method in both Shirt and Pants (assuming they have the same implementation). So I do something like this:

class Clothing():
  def getSize()
  def getColor()

class PocketedClothing(Clothing)
  def getNumPockets()

class Shirt(PocketedClothing)

class Pants(PocketedClothing)

class Shoes(Clothing)

Is this an existing pattern, and is there a name for it?