C++ :: Prototype Functions - Signed / Unsigned Incompatibility Error

Feb 17, 2013

I'm really brand new to C++ and I'm currently learning it for fun. I'm working on prototype functions, and I got an error.

I get an error saying “warning : '<' : signed/unsigned incompatibility” but I haven't defined an unsigned int anywhere. Actually, I don't even really know much about them except that they allow bytes from -127 to 127 instead of 0 to 256 for signed int's if I understood correctly...

The function itself is supposed to make a pointer go to the end of a string and add the Null Byte at the end. There's probably an already-existing way to do so, but I don't know it. Plus it is fun making this.

In the below code I'll be making comments for most lines so you may correct me if I'm not doing what I think I am. Any way, here's the code of my "my_fct.h" header file :

#include <stdio.h> //Includes basic functions necessary in C as 'scanf' or 'printf'.
#include <string.h> //Includes string functions such as 'strcpy' or 'strcmp'.
#include <iostream> //Not sure about what this does.
int strend(char[]); /* Specifies the existence of a function 'strend' that uses a char
* string as argument and that returns a value of integer type. */

[Code] ....

View 3 Replies


ADVERTISEMENT

C++ :: Dealing With Signed / Unsigned Mismatch

Oct 18, 2014

There are many questions on the web on how to fix a specific signed/unsigned mismatch, and the solution is usually just making one variable unsigned.

I have a grid (x,y) which should be unsigned, since you can't have a (-5,-3) sized grid. However, I have a Direction object which should be signed, since I can have a (-1, -1) direction. The problem is when I do something like Location_x + Direction_x > grid_x which throws the signed/unsigned mismatch warning.

View 13 Replies View Related

C :: Using Prototype Functions To Run Loops And To Pause The Program?

Oct 25, 2013

So i have to use these prototype functions to run loops and to pause the program, the only problem is after i select a loop option and enter a number of dots to print in the loop it goes into an infinite loop and why, also when i try using the 4 option to exit it still asks me how many dots i want to print.

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

int pause(char *);
int getInt(char *);
void whileFunction(int);
void doWhileFunction(int);
void forFunction(int);

[Code] .....

View 12 Replies View Related

C/C++ :: Getting Error Name Function Should Have Prototype

Aug 25, 2014

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
int i=1,j=2;
float k,l=1.5;

[Code] ...

View 3 Replies View Related

C/C++ :: How To Remove (Function Should Have A Prototype) Error

May 22, 2013

#include<iostream.h>
#include<conio.h>
int main() {
setcolor(BLUE);
setbkcolor(yellow);
cout<<"the text in blue colour with yelow background";
getch();
return 0;
}  

it keeps returning the same error always in my turbo c++ compiler . What is the correct program for changing background colour and text colour ...

View 1 Replies View Related

C++ :: Making Function To Read Unsigned Integer Into Variable Of Type Unsigned Short Int

Apr 3, 2014

How can i write a function that will read an "unsigned integer" into a variable of type "unsigned short int"? i can not use cin >> inside the function.. so i am looking for atleast a hint!

View 16 Replies View Related

C++ :: Setting All Bits Within Signed Int With Exception To MSB

Dec 26, 2013

I tried to write a little bit of code to set all bits within a signed int with exception to the MSB, yielding the greatest max positive value. The odd part is that it works for shorts ints, and longs, which are 2, 4 and 4 bytes respectively, however long longs, with a size of 8 bytes, simply yields -1, which would indicate that it failed to clear the MSB. Heres the little segment in question:

template<typename T>
T getMax() {
return my::numerics<T>::is_signed ?
~0 ^ (1 << ((sizeof(T)*8)-1) ):
~0;
}

my::numerics is just an exercise- its thoroughly tested and I'm certain thats not the issue.

For shorts, ints, longs, this yields the maximum value. However, when I use it on long longs, the output is 0xFFFFFFFFFFFFFFFF, i.e. ~0. Obviously this means the maximum value for unsigned long longs, but -1 for signed long longs.

View 2 Replies View Related

C++ :: Printf With Signed Short / Byte

Jul 17, 2012

I am using print/sprintf with a "%i" format string. Works fine if the input is indeed a 32bit integer. But how can i put in 8/16 bit (ie short & byte) 'integers'? If i just throw them in, they are always taken as unsigned, as the topmost bit/s is/are casted to zero... [URL] ....

View 3 Replies View Related

C++ :: Accept Signed Decimal Integer As Input And Output In Binary

Jan 29, 2015

Write a C++ application program to accept a signed decimal integer as input and output the equivalent 2s complement version in 16-bit binary. Include a space between every four bits in the output string. The input will only be processed by the application if it falls in the valid range that can be represented in 2s complement format with 16 bits. The range of a decimal number from - to + is -32768 to 32767.

View 3 Replies View Related

C++ :: Error Debugging With Functions?

Oct 7, 2014

I am remaking this code for my gain, and it seems that I cant debug the error..

Are there any comments on the structure of the code? Why are there errors in calling the functions?

#include <iostream>
#include <cmath>
#include <iomanip>

[Code].....

View 6 Replies View Related

C++ :: Getting Error C2678 With Overloaded Functions

Apr 22, 2014

I have 2 header files one contains my personType class which works independently as I created it for a previous lab and a binarySearchTree<Type> which allows you to create and do various functions with binary search tree's like inserting, searching,and deleting. Which also works independently usings numbers and strings. But when I have combined the 2 trying to make a binary tree of type personType I am running into this problem I can't seem to figure how to fix. The entirety of my code is provided for these 2 header files.

Error1error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)

PersonType
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include "orderedArrayListType.h"
#include "arrayListType.h"
using namespace std;

[code]....

View 12 Replies View Related

C :: Library Of Functions - Getting Error At Compile Time

Nov 19, 2013

So I made a library for a whole bunch of functions and when i compile it, it says"Unresolved external symbol_(Name of function here) referenced in function main.

View 1 Replies View Related

C++ :: WHILE Loop Error / In Streaming Data File (with Functions)

Nov 2, 2014

I have a working lab project with a loop error. Code posted in second post. Here's the requirements:

*
- program has to be able to handle file failure
- must loop (prefer to use a while loop here), read in the data, calculates values, etc. and then output the results.

*
The input data file includes

1. a 1 or a 0 indicating that there is a set of employee data following

2. the hourly rate of the employee

3. the humber of hours worked

4. the number of dependents

5. a 1 or a 0 indicating whether the employee is full time (1=full time).

Problem: At first I wouldn't loop back... so I moved the curly brace above the return0;

View 2 Replies View Related

C++ :: Output Vowel From User Input - Error With Strings And Functions

Nov 25, 2014

The program is supposed to read in a string from the user and then output the number of each vowel that the string has. My first function is initializing the vectors, and the one that I'm having trouble with is the function used to read the string from the user and save it.

Here's my code:

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

// FUNCTION PROTOTYPES GO HERE:
void init_vectors(vector<char> & vowels, vector<int> & frequencies);
string read_text(const string & prompt);

[Code] ....

And I'm getting the error:

freq.cpp: In function ‘std::string read_text(const std::string&)’:
freq.cpp:74: error: no matching function for call to ‘getline(std::istream&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’

I'm not too sure if I can't use the function getline here or if there is something wrong with the function prototype itself but I'm pretty sure there isn't an error there as it was given to me.

View 4 Replies View Related

C/C++ :: Print Single Linked List Backward With Functions / Classes - Error Message Regarding Header Files

Oct 11, 2014

I'm trying to print a single linked list backward with functions/classes. I have created the main file and 3 header files. But I'm getting an error on one of the header files, linkedListIterator after adding #include "linkedListType.h". It says that "linkedLlistType.h" is calling itself. And when I try to run it, I get an error of "too many header files." I have tried changing the headers many times, but nothing seems to work.

.cpp file:

/*(Printing a single linked list backward) Include the functions reversePrint and recursiveReversePrint, as discussed in this chapter, in the class linkedListType. Also, write a program function to print a (single) linked list backward. (Use either the class unorderedLinkedList or the class orderedLinkedList to test your function.)*/

#include "linkedListType.h"
#include "orderedLinkedList.h"
#include "linkedListIterator.h"
#include <iostream>
using namespace std;
struct nodeType

[Code] ....

header files:
[URL] .... (error in this header file)
[URL] ....

View 9 Replies View Related

C++ :: Copying Two Unsigned Char Into Unsigned Char

Mar 30, 2014

unsigned char key[32];
139 unsigned char rfseed[32];
173 f = fopen("/dev/urandom","rb");
174 fread(key,1,32,f);
175 fread(rfseed,1,32,f);

I am having problems copying outputs of the above code into other unsigned char other[32]. I need to keep the output of dev/urandom for backup. But, when I try to assign the values by memcpy(other, key, 32), the values do not match. The same problem happens by assigning values index by index in a loop.

View 2 Replies View Related

C++ :: Does Prototype Of Friend Function Has No Value?

Mar 30, 2013

[URL] ..... Prototype is commented.

[URL] ..... Prototype is included.

both give the correct output. Why?

View 2 Replies View Related

C :: Change Prototype For Generate Fibonacci

Apr 12, 2014

I have written this bit of code for the Fibonacci sequence.

Code:

9 int size=0;
10 int fib[DWORD];
11
}

[code].....

I have tried quite few things and I am trying to change the prototype for generate Fibonacci to... int* generateFibonacci(size). I have been trying to use calloc inside generateFibonacci and then declare a pointer in main that points at the address of the pointer that generateFibonacci returns.

View 9 Replies View Related

C++ :: Type Signature For Function Prototype

Mar 30, 2013

The function im having problems with takes an array where each element is an array of unsigned chars i.e. octals representing a bitmap of one of 95 ASCII code characters and searches through this two dimensional array looking for a match for a predetermined of array of unsigned chars i.e. the bitmap of a predetermined char. If we find the char the function outputs the index in the two-dimensional array where each elem. is an array of octals ELSE it return -1 i.e. when the char is not found.

I have 2 files, one .cpp, the other .h. There is a function named find_char. See INPUT and OUTPUT on line 48 in .cpp file.

The exception im getting is: font2.cpp:23:45:error: invalid conversion from unsigned char to unsigned char(*)[5]

The input type specified for my function prototype corresponding to find_char. If I put just unsigned char it doesn't fix the problem because it's an array parameter i.e. like a call by reference. I've lead myself to believe that the array variable contains a pointer to the first value in the array and so I've made function prototypes that work with a T* i.e. a pointer to type T. Making the function prototype argument unsigned char* i.e. a pointer to unsigned char simply gives me the exception: "invalid conversion from unsigned char to unsigned char*". When I have the argument be 'unsigned char' I get undefined reference to find_char(unsigned char). URL.....

View 1 Replies View Related

C++ :: Switching Function Prototype To Another Type

Mar 29, 2014

This is my code:

#include<iostream>
#include<string>
using namespace std;
int bin2dec(const string binarystring); // Declaration of bin2dec prototype with one string parameter
int main() {
cout << "Enter Q to terminate program.

[Code] .....

Right now the code is in the form of a 'const string binarystring' and were supposed to be able to use 'const char binarystring[]' and for some reason whenever i try to switch it i run into problems when referencing the main function to the int bin2dec(...) function.

I wanted to know if theres a simple way to switch the prototype to an array type of function with [] without changing the entire code.

View 7 Replies View Related

C++ :: Class Prototype - Generic Function

Aug 20, 2014

Let's first take the following class prototype:

#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
class Debugger;
class Debugger {

[Code] ....

My question is regarding the GetCurrentDebugLevel function above. Ideally I would like to use just one function to get the current debug level of the class, the std::string form would be used to save the "debugging level" in a settings file and the enumerated version would for evaluation purposes throughout the program.

My question is if implementing function prototypes by return value the best way to go or should I do something else?

View 4 Replies View Related

C++ ::  How To Initialize Function Prototype Of Array With Zero

Apr 23, 2014

We can initialize normal function prototype's parameters with zero like this:-

void output(float = 0.0, int = 0);

or

void output(int = 0, int = 0, double = 0.0);

But how do you do the same for a pointer array or simply an array?

Assume that second parameter has to be an array.

I have tried the following and it does not work:-

void output(float = 0.0, int = 0);
void output(float = 0.0, *int = 0);
void output(float = 0.0, int* = 0);
void output(float = 0.0, int[] = 0);
void output(float = 0.0, int []);

But if I skip the default declarations altogether, it works.

like:

void output(float, int []);

or

void output(float, int*);

how can I do it by explicitly writing zero, just like the first cases?

View 2 Replies View Related

C :: Prototype For A Function Accepting Variable Arguments

Dec 6, 2014

what should be the prototype for the following function.

Code:void addition(int x, ...);

I am getting compilation errors. I have written the prototype as :

Code: void addition(int, va_list);

View 3 Replies View Related

C :: Variably Modified Type - Function Prototype

Mar 24, 2013

Variably modified types are subject to certain restrictions , just as variable-length arrays are. The most important restriction is that the declaration of a variably modified type must be inside the body of a function or in a function prototype.

Code:
void f(int m , int n) {
int a[m][n] , (*p)[n];
p=a;
//....
}

What does it mean? That we can't declare such a pointer as a global variable?

View 4 Replies View Related

C :: Prototype Function Square Root Velocity

Mar 30, 2013

I am trying to computed the time it takes for a projectile to hit the ground. The problem is that i need to square the input of velocity before i do the calculation. the question I have is that if it's possible to have multiple arguments inside the brackets after main.

#include <stdio.h>
#include <math.h>
double distance (double a, double v, double g);
int square(int y);
double height(double v, double a, double g);
double time (double v, double a, double g);
double sqrt(double num);

[Code] ....

View 2 Replies View Related

C/C++ :: How To Make A Function Prototype That Uses Variables By Reference

Dec 4, 2014

How to how to make a function prototype that uses variables by reference. I'm making a decision based game where two running totals of two variables (ending and morality from decisions made) will decide the game outcome. I only have a few modules put in so far and most of the "story" parts cut down here to save space. I'm also getting an error saying there is more than one instance of overloaded function for the "whatToDo" module.

// ZombieGame.cpp : Defines the entry point for the console application.
//
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <iostream>
using namespace std;
//These are function prototypes to declare the functions being used
void WakeyWakey();
void TwentyMinsLater(int);

[Code] .....

View 2 Replies View Related







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