C :: Simple Get Function To Fill Instance In Structure

Apr 2, 2013

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct employee {
char firstName[20];
char lastName[20];
float rate;

[Code] .......

View 5 Replies


ADVERTISEMENT

C/C++ :: Simple Arkanoid Game - Deleting Instance Of A Class

Mar 24, 2015

I am making a simple arkanoid game. When the ball hits the block, i want the block to disappear. How would i go around this? i am working in visual studio. I got the collision and everything working.. Here is my code;

int main(int argc, char** argv){

//initialisation
SDL_Init(SDL_INIT_EVERYTHING);
SDL_WM_SetCaption("Graphics Window",NULL); //set name of project

//variable declaration
SDL_Surface*screen;
boolrunning;
intgameState;
float startTime;

[Code] ....

View 1 Replies View Related

C++ ::  Simple Program To Prepare Result Of N Students Using Structure

Jan 17, 2014

This is the program below..can you spot the errors in it.. I am getting lots of errors...!!

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct student {
char name[10];
int rollnumber,result
float m1,m2,m3,total

[Code] .....

View 12 Replies View Related

C :: Trying To Fill A Character Array With Scanf Function

Oct 5, 2014

I'm trying to make a character array, and be able to custom fill it by using the scanf() function to ask the user for each character spot in the array.

Code:
#include <stdio.h>
int main() {
int i;
char character_array[11];
char *charpointer;
charpointer = character_array;

[Code] .....

And this is the output i get when i run it:

Code:
root@kali-Tulips:~# ./myown
what letter would you like in the [0] spot of the array? :
a
what letter would you like in the [1] spot of the array? :
what letter would you like in the [2] spot of the array? :
b
what letter would you like in the [3] spot of the array? :
what letter would you like in the [4] spot of the array? :

[Code] .....

Obviously I'm trying to grasp C programming and am very new. I don't understand why this isn't working, and i think its more than my lack of knowledge of C syntax. I believe the correct memory is allocated but when examined with gdb i don't find what i expect....

View 4 Replies View Related

C :: Change / Fill List Without Changing Function Type

Feb 13, 2013

I am an IT student currently learning linked list. I have a problem with my code here. After I call addFront() my list doesn't change when I display it. How do I somewhat change/fill my list without changing the function type? I know it works on pointers still messed up with linked list.

Code:

typedef struct node *nodeptr;
struct node{int item;
nodeptr next;};
typedef nodeptr List;
}

[code]....

View 3 Replies View Related

C++ ::  Passing Class Instance To Function

Jan 17, 2014

I know that it is possible to pass a class instance to a function, but in my experience, if said function changes any variables of the class, they don't actually get changed. For example, we have class object, that has a member int number = 5. Lets say we have two functions, func1() and func2, which are not members of class object. If we pass object to func1() which, lets say, increases number by 5 (so now number = 10), at the end of that function number still = 5.

Is there a way to bypass this and have functions alter class variables permanently?

I know that I can pass variables by reference, but, in my experience, such a thing does not work with vectors (which I am also dealing with), so simple passing the desired variables by reference won't work.

View 5 Replies View Related

C/C++ :: Find Median Of Array Of 5 Values - No Instance Of Overloaded Function

Mar 12, 2014

I am so close to finishing this program. It will find the median of an array of 5 values. I have one last error that I cannot seem to get to go away. Here's the code:

#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
using namespace std;
int main() {
int integer1, integer2, integer3, integer4, integer5;

[Code] .....

The error states: "IntelliSense: no instance of overloaded function "std::nth_element" matches the argument list, argument types are: (std::_Array_iterator, std::_Array_iterator, unsigned int, std::_Array_iterator)

View 1 Replies View Related

C :: Create Function To Create A Dynamic Array That Fill With Randomly Generated Integers From 0 To 50

Oct 26, 2013

I have a struct called Array and I'm to create a function to create a dynamic array that's fill with randomly generated integers from 0 to 50 (inclusive) and a function to destroy the array for freeing its memory. Below the code that I have written so far.

Code:

* Struct */
typedef struct {int *pArray; //the dynamic array
int length; //the size of the dynamic array}Array;
/* Function to create a dynamic array */
Array *initializeArray (int length) {int i;
}

[code]....

View 7 Replies View Related

Visual C++ :: Circular Buffer - No Instance Of Overload Function Matches Argument List

Nov 25, 2014

I'm having some issues with my code. For the produce function i am getting an error saying 'no instance of overload function produce() matches the argument list' and also for the lines buffer[head].data = message; buffer[head].time = current_time i get an error saying 'expression must have pointer to object type.

In the code i'm not sure if i passed the variables to the function correctly. I have attached the code .....

code produce.txt

View 14 Replies View Related

C++ :: File IO Inside A Class - No Instance Of Overloaded Function Getline Matches Argument List

Jan 24, 2012

Hey I am trying to use the getline() function to read a line from a file. For some reason Visual Studio 2010 gives me the following error. "No instance of overloaded function "getline" matches the argument list". The piece of code that produces the error is in a class in a separate .h file and is executed as a method of the object. I'm almost certain it has something to do with either the compiler thinking I am calling another getline in a different namespace or my parameters for the function are incorrect. Here is the code:

Code:
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
class InsultGenerator

[Code] .....

View 1 Replies View Related

C :: Simple Calculation - Function To Do Factorization

Feb 8, 2014

I wrote a function to do factorization (n!). while this function works perfectly:

Code:
int fact (double x){
register int z=1;
if (x==0)
return 1;
else
for(x;x;x--)
z*=x;
return z;
}

this doesn't:

Code:
int fact (double x){
if (x==0)
return 1;
else
for(x;x;x--)
x*=x;
return x;
}

what makes the second one different from the first one? can't see the difference..

View 1 Replies View Related

C++ :: Construct Simple Hash Function?

Jun 3, 2013

How to construct a simple hash function ? When the program executes, it will ask for your name. Type your name and it will print out a "hash code" (a number) from that name.

View 2 Replies View Related

C++ :: Implement Simple Wrapper For Logging Function

Jul 22, 2014

I need to implement simple wrapper for logging function log(const char *). So the solution is below:

#include <stdio.h>
#include <sstream>
using namespace std;
void log(const char * str){ printf(str);}

[Code] ...

So, according to standard the temporary objects should not be destroyed before full expression execution (expression whitch is not a part of another expression).

The question is: is StreamLogger() << "foo1" << "foo2" << "foo3"; full expression or not?

View 2 Replies View Related

C :: Simplifying A Simple Linked List With Search Function

Jun 5, 2013

Code:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

struct node
{
int data;
struct node *next;

[Code] ....

It fills the singly-linked list with 0 through 9 and calls a function to prompt the user to search for a number. I don't see any glaring errors, I was just wondering what could be done to simplify it or if there's anything I missed.

View 8 Replies View Related

C :: Simple Valid / Invalid Function - Determine Either A URL Address Is Correct Or Not

Jul 13, 2013

I have to write a code which would determine either a URL address is correct or not.

Now, a valid address should look like: "www.something.something.uk".

It has to have 3 dots, 3 w-s in the beginning, and it must end with "uk".

E.g.

Valid addresses:
1. www.jce.ac.uk
2. www.tr2213.oi34.uk

Invalid addresses:
1. www2.jce.ac.uk
2. òæøéàìé - îëììä à÷ãîéú ìäðãñä éøåùìéí - ìéîåãé äðãñä ìúåàø øàùåï
3. www.something.uk

Just to be clear, this criteria mentioned above is not real, just homework

Code:
#include <iostream>
#include <string.h>
using namespace std;
int isValid (char s[])
{
int dots=0;

[Code] ......

It tells me both strings are incorrect but the first 1 is.

View 4 Replies View Related

C++ :: Class Function That Uses Instance Of Its Child Class As Argument

Mar 1, 2013

I am facing a real-life problem, it can be simplified as below:

#include <iostream>
using namespace std;
class B;
class A {
public:
void f1(A a) {}
void f2(B b) {}

[Code]...

There is no problem at all with the f1(), it compiles and executes without any problem. But f2() gives compilation error. How to solve this?

The error message is: error: 'b' has incomplete type This is just to define the function f2() in a class, that uses an instance of its child class as one of its arguments.

View 11 Replies View Related

C++ :: How To Print Structure With Function

Sep 19, 2013

I'm trying to pass my structure to a function using switch method, so that It will ask for user's name and age then then from the switch method it will call a print function, but my coding is not working.

View 7 Replies View Related

C :: Calling A Function With Structure Elements?

Mar 7, 2014

Code:
const MenuData breakfast[NUMOFBREAKFASTITEMS] = {
{"Egg Breakfast", "Two eggs with a side of bacon and two slices of toast.", "", "2 Eggs, 2 Toats, 2 Bacons", "", 250.00},
{"Pancake Breakfast", "Three Buttermilk pancakes served with butter and syrup.", "", "Three Pancakes, Butter, Syrup", "", 200.00},

[Code]....

What I'm trying to do is call the printReceipt function in the main, but I'm doing it wrong. Here is my attempt.

Code:
printReceipt (const MenuData menu[], qty, info)

I've tried it many other ways but I keep getting an error. I tried researching it on the internet, but I don't get much info.

View 14 Replies View Related

C :: Passing Structure Pointer To A Function

Aug 24, 2014

I am trying to wright a program that takes student grade data from a command line file, calculates a final grade, and copies the final grades to an output file. So far I have two functions, one that creates a student structure by allocating memory for it and returning its address, and one that should take that address and fill it with data from a line from the input file. My ultimate goal is to use a linked list to connect all the structs, but for now I just want to get the functions working. When I run what I have so far, I get an error C2440 (using visual 2010) that says "cannot convert from 'cStudent *', to 'cStudent', and points to the line where I call my fill function. How should structure pointers be passed?

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student // Declaring student structure globally.

[Code] .....

Also, here is a sample of what a line from the input file would look like:
Bill Gates, 60, 54, 38, 62, 65, 60, 50

View 2 Replies View Related

C/C++ :: Make A Structure For Date Containing Two Function

Jan 13, 2014

Make a structure for date containing two function one for increment Date() that add to date if day increase month also increase.

2nd for validation for date like day is not greater than 30 or 31.and validate the user input before user entered value.

I have done second. but no idea for first one. Any hint for increment date.

View 4 Replies View Related

C++ :: Passing Value From Function To Fields Of A Structure?

Jun 22, 2013

Is there a way of passing values gotten from a function into a fields of a struct?

Lets say you got a function that returns sum and square of some numbers. How can I assign those values to the new made struct?

struct Struct
{
int sum_from_func;
int square_from_func;
};

View 1 Replies View Related

C :: Returning Structure From A Function Using By Return Statement

Jul 14, 2014

I'm beginners in C Programming, i have a question about Structure in C. i know in Function it is possible for

1. Sending the value of argument
2. Sending the address of the argument
3. Returning values from a function by return statement

Does in Structure it is possible for

1. returning structure from a function using by return statement

View 2 Replies View Related

C++ :: Returning A Structure As Function Return Type

Apr 4, 2013

I am having problems with my function definition of a function that should return a structure value.

This is the error I get compute.cpp(9): error C2146: syntax error : missing ';' before identifier 's_advertisebus'

The error is on the line where I start my function definition typing my function type as a structure. A long time ago in c the keyword struct is used with the structure type like struct s_advertisebus s_readadbus(). I tried it both ways but I got errors.

// struct.h
#ifndef STRUCT_H
#define STRUCT_H

struct s_advertisebus {
int nnumberofads;
float fpercentused;

[Code] ....

View 2 Replies View Related

C++ :: Passing Nested Structure Array To Function

Feb 27, 2014

I've been able to write the program completing all requirements except for one... creating a function that accepts a nested structure array. Here's the program:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct PayInfo {
double hours; // Hours worked
double payRate; // Hourly payRate

[Code]...

I don't even know where to begin. Specifically, concerning all the aspects of the function.

View 5 Replies View Related

C++ :: Pass Pointer To Member Function (polymorphic Structure)?

Jan 3, 2015

I am trying to create a callback system for input events in my game engine.

Here is a cut down version of the EventManager.h file

#include "Controls.h"
#include "Object.h"
enum MouseEventType{PRESSED, POINTER_AT_POSITION, PRESSED_AT_POSITION };

[Code].....

This works if the function pointer being passed to the event manager is not a member function.

I have two other classes Scene and Object that could potentially use this EventManager to create callback events. Scene and Object are both pure virtual objects. How can I pass a pointer to a member function of the child classes of both Scene and Object? I am fine with just having two separate watchEvent functions for Scene and Object but how do I pass the type of the Object or the type of the Scene? The child classes are unknown as they are being created by someone using this game engine.

For example, if I want to make a player object it would be something like

class PlayerObject : public Object{...};

Now that PlayerObject type has to find its way to PlayerObject::functionToCall(). I think I need templates to do this but, since I never used them before

This is how I intend to use this

class OtherScene : public Scene{
void p_pressed(void){
//pause
}

[Code].....

View 6 Replies View Related

C/C++ :: Not Able To Initialize Structure Variable Inside Main Whose Structure Defined GL

Aug 27, 2013

I am trying to run a programme implementing a function with structures in c... which is:

#include<stdio.h>
#include<conio.h>
struct store  {
        char name[20];
        float price;    
        int quantity;

[Code] .....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved