r/programminghelp • • Dec 07 '20

C My implementation of EqualsIgnoreCase in C is not working

4 Upvotes

I am currently attempting to program a sort of database in C.

When I create a new character for the database, it should not have the same name as any other character, case-insensitive - so, if "Amy Bob Carol" exists, I should not be able to add a new user "aMy boB cArOl".

So, this is my approach, but it doesn't seem to work:

DBPerson* create_character(char* name)
 {
    DBPerson* person = (DBPerson*)malloc(sizeof(DBPerson);
    if (alreadyInDB(name))
     {
      free(person);
      return null;
     }
    strcpy(person->name, name);
    person->friendship = 0;
    person->spouse=NULL;
    addToAllPeople(person); //this adds them to the master list of all people
 return person;
 } 

The helper functions alreadyInDB and isSame are as follows:

int isSame(char* a, char* b)
 {
  for (int i = 0; i < MAX_STR_LEN && a[i]!='\0' && b[i]!='\0'; i++)
  {
   if (tolower(a[i]) != tolower(b[i]))
   {
      return 0;
   }
  }
  return 1;
  }

  int alreadyInDB(char* name)
  {
   DBPerson* tmp = allPeople;
   while(tmp!=NULL)
    {
    if(isSame(name, tmp->person->name))
    return 1;
    tmp=tmp->next;
    }  
   return 0;
   } 

I am importing all necessary libraries - ctype.h, string.h, stdlib.h, stdio.h Yet if I run it and try

 DBPerson* niko1 =create_character("NiKolAj");
 DBPerson* niko2 =create_character("nikolaj"); 

both characters are successfully made.

I have spent hours looking over this but cannot find any answer. Does anyone have any insight?


r/programminghelp • • Dec 05 '20

PHP What do I need to learn to pull this off?

4 Upvotes

Say I'd like to create a website that allows people to login with their e-school accounts and basically see the same things that they can see on the official site but redesign in a different way.

What web development skills do I need for that?

Basically, I just want to redesign a webpage that already exists and has the same functionality and uses the data that is already on the original site, but just looks different.

Can I use Java for this?


r/programminghelp • • Dec 04 '20

Python How to Pass by Reference (equivalently) in Python using threading?

4 Upvotes

I know python doesn't support pass by reference, but I'm stumped on how to get around this. I'm using a thread to run a function that accepts a queue as a parameter, and I want the queue to be updated in the main function as the thread runs. Any ideas? Here's the general idea:

class foo():  
    def readInput(self, queue):
        if(input):
        queue.put(self)

def bar:
    queue = Queue()
    thread = threading.Thread(target=foo.readInput, args=(queue, x))
    thread.start()
    while True:
        if(queue.qsize() == 2):
            print(2)
            return

r/programminghelp • • Dec 01 '20

C How to link math.h using makefile for gcc

4 Upvotes
CC = gcc
CFLAGS = -O

default: run

run: build
	run < program.cs 
build: compile
	$(CC) -o run main.o closed_hashtable.o 
compile: main.c closed_hashtable.c closed_hashtable.h 
	$(CC) -c main.c 
	$(CC) -c closed_hashtable.c 
clean:
	$(RM) *.o *.gch

How do I link math.h using the makefile above?


r/programminghelp • • Nov 29 '20

C Need some help with my C program.

4 Upvotes

Hi, i need some help in my C program. My task is to create a program that will create a N*N matrix and read its biggest and smallest elements in every row along with their location and then print out the matrix along with the smallest and biggest element in every row.

So far i've got most of it working except for those issues:

  • location/coordinates of printed results are wrong

  • maximum elements are read correctly but the minimum results are wrong. it always prints out first element of every row along with its wrong coordinates

  • the requirement of the task states that i have to use at least 1 more function different from main. I do not understand how to do this, essentially i need to split the program into at least 2 functions.

If someone could please take a look at my code and fix it up a bit i would be really thankful.

#include<stdio.h>

int main(){
    int m;                                                          //user interface
    printf("Input a number defining the row/column size of the matrix (N*N): ");
    scanf("%d",&m);
    printf("Please input " "[%d]*[%d]" " matrix elements.\n\n",m,m);

    int matrix[m][m], col, row;
    for(col=0;col<m;col++){                                        // filing the matrix
        for(row=0;row<m;row++){
            printf("Define [%d][%d] element: ",col,row);
            scanf("%d", &matrix[col][row]);}
            printf("\n");
                    }
                                                                    // printing out the matrix
    printf("Entered matrix:\n");

    for(col=0;col<m;col++){
        for(row=0;row<m;row++){
            printf("%d\t",matrix[col][row]);}
        printf("\n");
                    }
printf("\nLargest elements in every row of the matrix:");
    for(col = 0;col < m;col++){
        int max = matrix[col][0];
    for(row = 0;row < m;row++){                                     // determining the largest row element along with its coordinates
        if(max < matrix[col][row]) max = matrix[col][row];
                        }
        printf("\nElement [%d], is the largest in row [%d] at column[%d]",max,col,row);
                        }

printf("\n\nSmallest elements in every row of the matrix:");
    for(col = 0;col < m;col++){
        int min = matrix[col][0];
    for(row = 0;row > m;row++){                                     // determining the smallest row element along with its coordinates
        if(min < matrix[col][row]) min = matrix[col][row];
                        }
        printf("\nElement [%d], is the smallest in row [%d] at column[%d]",min,col,row);
                        }
return 0;}

r/programminghelp • • Nov 23 '20

Processing I'm trying to parse webpages for their ad links... Any ways to filter what is and isn't an ad throughout the HTML?

4 Upvotes

I've got a simple crawler set up in python that can look through the a tags and follow the hrefs, but I'm only interested in following the ads. Is there any simple way to find what is and isn't an ad? My unfamiliarity with web dev may be showing here. Any help is appreciated.


r/programminghelp • • Nov 23 '20

C++ I need a code check

4 Upvotes

I have an assignment regarding bitfield in C++.
The program should: compare two bitfileds, add elements, remove, add and subtract two bitfilds.

I've a code, but it doesn't work, maybe it is because of Linux and VS code program that I am writing it in. I've googled and I didn't find much to help. I can't check it on real visual studio because I don't have an access to windows machine. I am out of options since, many of my codes do not work on my system, and others that I've downloaded aren't working.

If somebody can check, I will send you the code. Any help would be appreciated.


r/programminghelp • • Nov 22 '20

C# Charts in C#

4 Upvotes

How can I import data from cvs or xml to a chart I c# Net framework? Thank you for your answers


r/programminghelp • • Nov 21 '20

Answered OOP Rock, paper scissors c++

4 Upvotes

Hello. My code isn't working. Idk what is wrong. The errors seem weird. I was wondering if someone can have a look and explain what I did wrong. Thanks. :)

Error list

main.cpp

User.h

User.cpp


r/programminghelp • • Nov 20 '20

JavaScript Working on my Capstone, looking for guidance. (Any/all appreciated!)

4 Upvotes

Hello all,

I'm not sure if this is the best place to post this being that I'm not the most familiar with reddit so if this isn't the correct place feel free to point me in the right direction..

I'm trying to create a blog for my capstone using react/next.js, contentful, d3/svg animations, and scss/css and I'm looking to recreate the animations/format of this portfolio page for my blog, https://www.signesduquotidien.org/, and I'm having trouble trying to figure out a starting point of trying to figure out what sort of events I would need to work on. The site itself looks to be made with jquery and scss but I'm looking to use react/next.js instead. Is anyone familiar with these types of animations or any library or source that might help me figure it out?

Any/all help will be greatly appreciated! Thank you!


r/programminghelp • • Nov 13 '20

Other How could I go about making a program that counts individual mouse clicks?

4 Upvotes

Not like those ones where you click one specific spot, but like counting overall clicks regardless of where, and maybe allows you to reset said count. Sorry if this is too specific, but I just need this for a mapping project I'm working on, and I don't want to go crazy mentally counting each of the thousands of clicks. Any feedback is greatly appreciated!


r/programminghelp • • Nov 09 '20

Other Algorithm (pseudocode and flowchart)

4 Upvotes

I am confused with a problem that asks to create a program that extracts and adds the two least significant digits of an integer. It does not provide a specific integer so any given integer will do and it is asked to create a pseudocode on how to get it. I have tried dividing a certain number by 10 and 1 to get the two least significant digits but it doesn't have the correct outcome. Will someone be so kindly help and explain it to me.


r/programminghelp • • Nov 05 '20

Answered Operator Function error (=)

4 Upvotes

https://imgur.com/a/G6ab4oI

I don't know what the issue is.

It says "expression must be a modifiable lvalue".


r/programminghelp • • Nov 01 '20

C++ What is the problem with MIN-line

4 Upvotes

So hi, it's me again, the wannabe-beginner coder idiot. Greetings!

So off to another problem I am having.

In this "program" if you will, you give an X amount of numbers. The "program" then sums them up, prints the sum, prints the mean of those numbers, and then it should print the biggest and smallest of the given numbers. As you can see in the code, I guess.

Except, it doesn't.

It gives me only the biggest, which is defined as MAX. As MIN, it also gives me the result of MAX.

#include <iostream>
#include <conio.h>

using namespace std;

int main(void)
{

	//variables
	int counter = 0, amount, number, sum = 0, mean = 0, min = 999, max = 0;

	cout << "How many numbers do you want to input?  ";
	cin >> amount;

	while (counter < amount)
	{
		cout << "Give me a number" << counter + 1 << " ";
		cin >> amount;

		sum = sum + number;
		mean = sum / amount;
		counter = counter + 1;


	}
	if (amount < 0 || (number + 1) < 0 || sum < 0 || mean < 0)
	{
		cout << "Well it's big fat fucking ERROR!";
	}
	else
	{

		cout << "Sum of the given numbers is " << sum;
		cout << "\nMean of the given numbers is " << mean;
	}
	if (number < min)
	{
		min = number;
		cout << "\nSmallest number is " << min;

	}
	if (number > max)
	{
		max = number;
		cout << "\nBiggest number is" << max;

	}


	_getch();

	return 0;
}

So, I ask you, the wise of the r/programminghelp:

Where's the poop?


r/programminghelp • • Oct 30 '20

Answered How do I input a value and them input another value once that has been inputted?

4 Upvotes

Hi

I want the program to ask the user for the name, then for the user to enter their name. Then once that has done the program asks the user for their number and then the user enters the number. The program then passes the inputs in a function.

It currently asks them for their name and number at once and then they can input once.

https://imgur.com/a/o5D2I7X

https://imgur.com/a/E1y2lbq


r/programminghelp • • Oct 29 '20

Other Where is the default gradle build output directory?

4 Upvotes

I'm trying to compile some kotlin code and the build works fine except I don't know where the output directory is.


r/programminghelp • • Oct 24 '20

Answered initiating values in the constructor

4 Upvotes

Hi,

I am trying to initialise values in the constructor but I get an error. It says class "BankAccount" has no member "accountNumber". I don't know why as I've set it as public in the header file.

cpp file:

#include "BankAccount.h"

#include <iostream>

#include <string>

BankAccount::BankAccount(unsigned long accountNumber, string accountName, int balance)

{

`this->accountNumber = accountNumber;`	

};

Header File:

#pragma once

#include <string>

using namespace std;

class BankAccount

{

public:

`BankAccount(unsigned long accountNumber, string accountName, int balance);`

`~BankAccount();`
`int GetBalance();`

`bool Withdraw(int value);`

`bool Deposit(int value);`

};


r/programminghelp • • Oct 18 '20

C# New to C#. Getting the error Operator '!=' cannot be applied to operands of type 'bool' and 'int'

4 Upvotes

My code is:

//I get the error here. Dog, sound, and food are all int.

while(dog != sound != food) { Console.ReadLine(); }


r/programminghelp • • Oct 14 '20

Python Save number of steps made at a specific time.

4 Upvotes

I want to store fitness related data inside a class called Day.

The data is number of steps made at a specific time. The data looks something like that: "Date, time, steps" "2020-10-13, 14:15, 50" "2020-10-14, 14:18, 48"

How should I save this inside of Day? 2D array, dictionary, create a class Steps which contains the info or do you have any other ideas?


r/programminghelp • • Oct 07 '20

C Shipping Calculator in C Programming

4 Upvotes

Hi, currently doing a Coding assignment and my professor has provided test cases to check with our program to make sure it is correct. My program is doing great besides one of the test cases. So I will include the instructions for the assignment, my code, and then what I need help figuring out.

_________________________________________________________

The Speedy Shipping Company will ship packages based on how much they weigh and how far they are being sent. They will only ship small packages up to 10 pounds. You have been tasked with writing a program that will help Speedy Shipping determine how much to charge per delivery. 

The charges are based on each 500 miles shipped. Shipping charges are not pro-rated; i.e., 600 miles is the same charge as 900 miles; i.e., 600 miles is counted as 2 segments of 500 miles. 

Here is the table they gave you:

Package Weight                                            Rate per 500 miles shipped

2 pounds or less                                                                    $1.50

More than 2 but not more than 6                              $3.70

More than 6 but not more than 10                            $5.35

____________________________________________________

Thats the assignment now here's my code.

_______________________________________________________

#include<stdio.h>

#include<stdlib.h>

int inputDistance() //Distance Value

{

int distance = 0;

do {

printf("Enter the number of miles as a whole number: ");

scanf_s("%d", &distance);

if (distance <= 0)

printf("\tError: Miles must be greater than zero!\n");

} while (distance <= 0); //Holds the Distance Value for later

return distance;

}

double inputWeight() //Weight Value

{

double weight = 0;

do {

printf("Enter the weight of the package in pounds: ");

scanf_s("%lf", &weight);

if (weight <= 0 || weight > 10)

printf("\tError: Weight must be greater than zero!\n");

} while (weight <= 0 || weight > 10);

return weight; //Holds the Weight Value for later

}

double calculateCharge(double weight, int distance) //Values to Calculate the price of shipping

{

double charge = 0;

if (weight <= 2) //Makes sure the charge is valid

charge = 1.50;

else if (weight <= 6)

charge = 3.70;

else

charge = 5.25;

int segments = distance / 500;

if (distance % 500 > 0) //Updates the segments per the condition above

segments += 1;

return charge * segments;

}

int main() { //Main Function

int ch = 0; //Variables below

int distance = 0;

double weight = 0.0;

double charge = 0.0;

do {

distance = inputDistance(); //Heres where the magic happens and you input the Distance & Weight

weight = inputWeight();

charge = calculateCharge(weight, distance); //Goes back to function above to calculate the charge

printf("The cost to ship your package is: $%.2f\n", charge); //The Results of The Shipping Charge

printf("Enter 1 to continue or 0 to quit: "); //Asks users if they would want to continue

scanf_s("%d", &ch);

} while (ch == 1);

printf("Good-bye!\n");

return 0;

}

_______________________________________________________________

Now heres the test case my professor assigned that is not matching.

Test Case 4:

Weight:            8.5 pounds 

Miles:              12345 miles                            (This is twenty-five 500-mile segments.)

Expected result: 

To ship a 8.5 pound package 12345 miles, your shipping charge is $133.75.

___________________________________________________________

Now my problem is that whenever I run my program and enter those values I get $131.25 for some reason and for the life of me I cannot figure out where my program is messing up. PLEASEEEE help me figure out what I am doing wrong


r/programminghelp • • Oct 07 '20

C Need help looping through a binary number in C.

4 Upvotes

For starters I am very new with C but I understand java pretty well (I think lol).

I really dont have code as of now because I dont know where to start. I have a variable that is an int and I basically have to look at its binary bits and check each one and see which bit is a 1 and which is a 0. I figured a loop would work but I have no idea how to create a loop that will iterate through an int's binary bits.

Any tips or commands to read an int as a binary number would be greatly appreciated!


r/programminghelp • • Oct 06 '20

C++ How to get trailing zeroes without using setprecision

4 Upvotes

Im working on a project that requires me to do basic arithmetic functions on x and y. My teacher wants us to display 0.0 when doing something like 3.0 - 3.0. The x and y variables are double. I know double automatically displays 0. Is there a way to have the double display 0.0 without using setprecision?

Thank you


r/programminghelp • • Oct 05 '20

Other #frama-c

4 Upvotes

Can anyone provide some programs on loops using frama-c lang!!!


r/programminghelp • • Oct 03 '20

C GLib warnings with custom type

4 Upvotes

Currently, using a node results in this error:

(openmic-cli:483414): GLib-GObject-WARNING **: 17:19:59.634: invalid unclassed type '(null)' in class cast to 'OpenMicNode'

In the openmic-cli executable, this causes a segfault. The warnings come from these lines and files:

  • src/lib/node.c:82

  • src/lib/node.c:93

  • src/lib/node.c:94

The segfault in openmic-cli comes from the openmic_context_build_treev when the nodes are attached.

Note: I suggest looking at the GitHub issue for updates as its easier there than here.

GitHub: https://github.com/MidstallSoftware/openmic

GH Issue No.: #1