Invalid conversion from char* to char


 
Thread Tools Search this Thread
Top Forums Programming Invalid conversion from char* to char
# 1  
Old 03-29-2014
Invalid conversion from char* to char

Pointers are seeming to get the best of me and I get that error in my program.
Here is the code

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

#define REPORTHEADING1 "     Employee              Pay      Hours     Gross     Tax       Net\n"
#define REPORTHEADING2 "     Name                  Rate     Worked    Pay       Due       Pay\n"
#define REPORTHEADING3 "     ===============       ====     ======    =====     ====      ====\n"
#define REPORTHEADING4 "                           ====     ======    =====     ====      ====\n"
#define REPORTLINEFORMAT1 "     %-20s%6.2f%11.2f%9.2f%9.2f%10.2f\n"
#define REPORTLINEFORMAT2 "     Totals              %6.2f%11.2f%9.2f%9.2f%10.2f\n"
#define REPORTLINEFORMAT3 "     Averages            %6.2f%11.2f%9.2f%9.2f%10.2f\n"


#define COUNTLINEFORMAT "     Number of employees: %-10i\n\n"

#define MAXREGHOURS 40
#define OVERTIMERATE 1.5



void PrintReportHeadings(FILE *reportFile); //printReportHeadings prototype

void InitializeAccumulators(float *totRegHour,float *totOvtHours,float *totPayrate, 
		float *totGross,float *totdeferred,float *totFedtax,
		float *totStatetax,float *totSSItax,float *totNet,int *empCount); //InitializeAccumulators prototype

void InputEmployeeData(char *firstName,char *lastName,
			float *hours,float *payrate,float *deferred); //InputEmployeeData prototype

void CalculateGross(float hours,float payrate,float *regHours,float *ovtHours,
			float *gross); //CalculateGross prototype

extern void CalculateTaxes(float gross,float deferred,float * fedtax,
				float * statetax,float * ssitax); //CalculateTaxes prototype (external)

float CalculateNetPay(float gross,float fedtax,float statetax,float ssitax,
                float deferred);

void AddDetailToAccumulators(float regHours,float ovtHours,float payrate,
		float gross,float deferred,float fedtax,float statetax,
		float ssitax,float net,float *totRegHours,float *totOvtHours,
		float *totPayrate,float *totGross,float *totdeferred, 
		float *totFedtax,float *totStatetax,float *totSSItax,
		float *totNet);

void PrintSummaryReport(FILE *reportFile,char fullName,float regHours,float ovtHours,
			float payrate,float gross,float deferred,float fedtax,
			float statetax,float ssitax,float net);

int main(void)
{
	float ft,st,ssit;
	char firstName[10+1];
	char lastName[15+1];
	char fullName[25+1];
	float regHours, ovtHours, hours, payrate, deferred, gross, netpay;
	float totRegHours, totOvtHours, totPayrate, totGross,totdeferred, 
		totFedtax, totStatetax, totSSItax, totNet;
	int empcount;
	char answer;
	FILE * reportFile;

	reportFile = fopen("./report.txt","wt");
	if(reportFile == NULL) 
	{
	    printf(" Report open request failed...\n");
	    while(getchar() != '\n');
	    exit(-90);// reqs <stdlib.h>
	}

	PrintReportHeadings(reportFile);

	InitializeAccumulators(&totRegHours,&totOvtHours,&totPayrate,&totGross,
		&totdeferred,&totFedtax,&totStatetax,&totSSItax,&totNet,
		&empcount);//set all accumulators to 0

	do
    {
	InputEmployeeData(firstName,lastName,&hours,&payrate,&deferred);
	CalculateGross(hours, payrate, &regHours, &ovtHours, &gross);
	CalculateTaxes(gross,deferred,&ft,&st,&ssit);
	netpay = CalculateNetPay(gross,ft,st,ssit,deferred);
    strcpy(fullName,lastName);
	strcat(fullName,", ");
	strcat(fullName,firstName);

	AddDetailToAccumulators(regHours,ovtHours,payrate,gross,deferred,ft,st,
		ssit,netpay,&totRegHours,&totOvtHours,&totPayrate,&totGross,
		&totdeferred,&totFedtax,&totStatetax,&totSSItax,&totNet);

	PrintSummaryReport(reportFile,fullName,regHours,ovtHours,payrate,gross,deferred,ft,st,ssit,netpay);

	empcount++;
	printf(COUNTLINEFORMAT,empcount);

	printf("  do you have anymore? (Y/N): ");
	while(getchar() != '\n');
	answer = getchar();
	printf("\n");

	}
    while(answer != 'N' && answer != 'n');

	while (getchar()!= '\n');
	getchar();
	return 0;
}

void PrintReportHeadings(FILE *reportFile)
{
        reportFile = fopen("./report.txt","wt");
        fprintf(reportFile,REPORTHEADING1);
        fprintf(reportFile,REPORTHEADING2);
        fprintf(reportFile,REPORTHEADING3);
}


void InitializeAccumulators(float *totRegHour,float *totOvtHours,float *totPayrate,
                float *totGross,float *totdeferred,float *totFedtax,
                float *totStatetax,float *totSSItax,float *totNet,int *empCount)
{
        totRegHour, totOvtHours, totPayrate, totGross,totdeferred,
                totFedtax, totStatetax, totSSItax, totNet, empCount = 0;
}

void InputEmployeeData(char *firstName,char *lastName,float *hours,
			float *payrate,float *deferred)
{
	printf("  Enter employee first name : ");
	scanf("%s",firstName);
	printf("  Enter employee last name : ");
	scanf("%s",lastName);
	printf("  Enter %s's hours worked : ",firstName);
	scanf("%f",hours);
	printf("  Enter %s's pay rate : ",firstName);
	scanf("%f",payrate);
	printf("  Enter %s's amount deferred : ",firstName);
	scanf("%f",deferred);
}

void CalculateGross(float hours,float payrate,float *regHours,float *ovtHours,float *gross)
{
float overtimeHours(float hours);

	if(hours <= MAXREGHOURS)
	{
		*regHours = hours;
		*gross = hours * payrate;
	}
	else
	{
		*regHours = MAXREGHOURS;
		*ovtHours = overtimeHours(hours);
		*gross = payrate * MAXREGHOURS + OVERTIMERATE * payrate * (hours - MAXREGHOURS);
	}
}

float overtimeHours(float hours)
{
	return hours - MAXREGHOURS;
}
float CalculateNetPay(float gross,float fedtax,float statetax,float ssitax,
		float deferred)
{
	return gross - (fedtax + statetax + ssitax + deferred);
}
void AddDetailtoAccumulators(float regHours,float ovtHours,float payrate,
                float gross,float deferred,float fedtax,float statetax,
                float ssitax,float netpay,float *totRegHours,float *totOvtHours,
                float *totPayrate,float *totGross,float *totDeferred,
                float *totFedtax,float *totStatetax,float *totSSItax,
                float *totNet)
{
	*totRegHours =+ regHours;
	*totOvtHours =+ ovtHours;
	*totPayrate =+ payrate;
	*totGross =+ gross;
	*totDeferred =+ deferred;
	*totFedtax =+ fedtax;
	*totStatetax =+ statetax;
	*totSSItax =+ ssitax;
	*totNet =+ netpay;
}

void PrintSummaryReport(FILE *reportFile,char fullName,float regHours,float ovtHours,
                        float payrate,float gross,float deferred,float fedtax,
                        float statetax,float ssitax,float netpay)
{
	reportFile = fopen("./report.txt","wt");

	fprintf(reportFile,REPORTLINEFORMAT1,fullName,payrate,regHours,gross,fedtax,
		ssitax,netpay);
	fprintf(reportFile,REPORTLINEFORMAT2,ovtHours,statetax,deferred);

	
}


More specifically, the error is for this line
Code:
	PrintSummaryReport(reportFile,fullName,regHours,ovtHours,payrate,gross,deferred,ft,st,ssit,netpay);

# 2  
Old 03-29-2014
In the PrintSummaryReport function prototype and definition, fullName should be should be 'char *' not 'char'.

In case this is an important task and you aren't aware, from the initial scanf to subsequent strcpy and strcat operations, there's a lot of unsafe string handling in your code.


Regards,
Alister

Last edited by alister; 03-29-2014 at 04:26 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Bool vs char * conversion

I have a problem at make step to install a downloaded package consisted of different programs. In file included from kcdbext.cc:16:0: kcdbext.h: In member function �char* kyotocabinet::IndexDB::get(const char*, size_t, size_t*)’: kcdbext.h:1281:14: error: cannot convert �bool’ to... (3 Replies)
Discussion started by: yifangt
3 Replies

2. Shell Programming and Scripting

awk script throws invalid char expression

Hello there, I am new to the awk scripting and getting the following error while running the script. Please can you advise me how to resolve this . Thanks ./sub_del_awk_lat.sh awk: cmd. line:5: warning: escape sequence `\/' treated as plain `/' awk: cmd. line:5: sed -n... (6 Replies)
Discussion started by: Sudhakar333
6 Replies

3. Programming

Double to const char conversion

Dear all, I am using C and ROOT for programming. And I need to incorporate following in my code. char *fps=NULL; int dec=0,sign=0; float mean = h1->GetMean(1); //0.001298 fps= fcvt(mean,6 , &dec, &sign); I need to provide this mean as const char to some other function to get... (8 Replies)
Discussion started by: emily
8 Replies

4. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

5. Programming

conversion to 'char' from 'int' warning

Hi, I wrote a simple code in C++ converting from UpperToLower case characters. However, my compiler gives me a warning: "warning: conversion to 'char' from 'int' may alter its value". Any tips? I would like to stress, I don't want to load my string into char array. int ToLower(string... (4 Replies)
Discussion started by: kajolo
4 Replies

6. Shell Programming and Scripting

Non-ASCII char prevents conversion of manpage to plain text

Hello, I would like to export manual pages to plain text files. man CommandName | col -bx > CommandName.txt The above statement works successfully on Mac OS X. However, it often fails on my old Linux. The problem occurs if the source file of the manpage contains an escape sequence for... (5 Replies)
Discussion started by: LessNux
5 Replies

7. Programming

concat const char * with char *

hello everybody! i have aproblem! i dont know how to concatenate const char* with char const char *buffer; char *b; sprintf(b,"result.txt"); strcat(buffer,b); thanx in advance (4 Replies)
Discussion started by: nicos
4 Replies

8. Programming

Adding a single char to a char pointer.

Hello, I'm trying to write a method which will return the extension of a file given the file's name, e.g. test.txt should return txt. I'm using C so am limited to char pointers and arrays. Here is the code as I have it: char* getext(char *file) { char *extension; int i, j;... (5 Replies)
Discussion started by: pallak7
5 Replies

9. UNIX for Dummies Questions & Answers

ANSI C, char to hex conversion

Hi, I have a char buf,ch; and the buf is filled with the result from MySQL server which I get like this numbytes = recv(sock, buf, 1024, 0));I have the followingcode to display the results printf("received %ld bytes:\n",numbytes); for(c=0;c<numbytes;c++){ ch = (char)buf; ... (2 Replies)
Discussion started by: alikims
2 Replies

10. Programming

char to int64 conversion

Hi, I'm converting a C program that I made using the Visual Studio. I now use GCC (over Linux) and can't find some equivalences. I changed my __int64 definitions to unsigned long long, but can't find an equivalent to the microsoft i64toa() function, which let you convert a char* to a 64 bit... (1 Reply)
Discussion started by: Raspoutine
1 Replies
Login or Register to Ask a Question