10 Replies - 917 Views - Last Post: 05 October 2012 - 10:34 AM Rate Topic: -----

#1 bradleycmetz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-September 12

passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 09:30 AM

Hello! I am trying to read in an inventory type, and the number of each of those types, then if there already exists that certain inventory type, add the number of additional items to that spot in the array. I have an idea of what is going wrong but I cannot pinpoint the issue. It has something to do with my variables- chars and integers and the lack of pointers. I'm not sure that the logic is correct, but I can change that when I get strcpy and strcmp to act correctly

#include <stdio.h>
#include <string.h>

int main(void){
    
    int choice,don,i,n,numdon=0,numreq=0   ;
    char dontype[100][20],reqtype[100][20],temptype[20]  ;/*issue here?*/
    int donamount[100],donamt,reqamount[100]   ;
if (choice==1)
          {
          printf("How many donations do you have?\n");
          scanf("%d",&don);
                for (i=don;i<don;i++)
                {
                printf("\nPlease enter your donation type.\n");
                scanf("%s",&temptype[i]);
                printf("Please enter your donation amount.\n");
                scanf("%d",&donamt);
                    if (numdon==0) 
                    {
                    (strcpy(dontype[i],temptype[i]));
                    donamount[i]=donamt;
                    numdon++;
                    printf("Donation added.\n\n"); 
                    }  
                    else if (numdon > 0)
                    {            
                        for (n=0;n<numdon;n++)
                        {
                            if (strcmp(temptype[i],dontype[n])== 0)
                            {                                 
                               donamount[n]=donamount[n]+donamt);/*issue here?*/
                               numdon++;    
                               printf("Donation added.\n\n");
                            }
                            else if (strcmp(temptype[i],dontype[n])!= 0)
                            {
                               strcpy(dontype[i],temptype[i]);/*issue here?*/
                               donamount[i]=donamt;
                               numdon++;
                               printf("Donation added.\n\n");                               
                            }                        
                        }
                    }                
                }
          }
    

I feel like the answer is right under my nose as always, but I'm just so burnt out right now!
Thanks- as always- for the help.

Is This A Good Question/Topic? 0
  • +

Replies To: passing arg 2 of `strcpy' makes pointer from integer without a cas

#2 Duta  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 21-June 12

Re: passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 09:41 AM

With the strcpy & strcmp issues, ask yourself what types you're trying to pass to them, and what types they are expecting.
With the issue on line 32, you have a random closing parenthesis after donamt.
I believe you're also missing a closing curly bracket at the end of the file, but that may just be a bad copy/paste.
Was This Post Helpful? 0
  • +
  • -

#3 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 09:44 AM

Just a quick look at your code, and I seen this:
for (i=don;i<don;i++)


If i is initialized to don then how it could become less than don? The loop won't iterate, I guess..
Was This Post Helpful? 1
  • +
  • -

#4 bradleycmetz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-September 12

Re: passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 09:49 AM

View PostDuta, on 05 October 2012 - 09:41 AM, said:

With the strcpy & strcmp issues, ask yourself what types you're trying to pass to them, and what types they are expecting.
With the issue on line 32, you have a random closing parenthesis after donamt.
I believe you're also missing a closing curly bracket at the end of the file, but that may just be a bad copy/paste.


With all due respect I don't exactly know what you mean by pass to them. I'm trying to compare chars, and if they are equal to 0, do a statement if they are unequal to 0, do another statement.
I found the bracket in there and removed it, compiled and it ran but when it got to the if/else regarding the strcmp/strcpy it stopped working. I'm not too sure. It may be an error in my fundamentals that I cannot point out because I do not know any better. I'll take a closer look and re-reread the lecture notes on strings to see if I find anything! Thanks!

View PostAKMafia001, on 05 October 2012 - 09:44 AM, said:

Just a quick look at your code, and I seen this:
for (i=don;i<don;i++)


If i is initialized to don then how it could become less than don? The loop won't iterate, I guess..


This is true I caught that after I posted. It is compiling and running, the only thing is the issue comparing and copying strings.. I'm close to figuring it out, I just need to find the right piece of info =P
Was This Post Helpful? 0
  • +
  • -

#5 bradleycmetz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-September 12

Re: passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 09:56 AM

View PostAKMafia001, on 05 October 2012 - 09:44 AM, said:

Just a quick look at your code, and I seen this:
for (i=don;i<don;i++)


If i is initialized to don then how it could become less than don? The loop won't iterate, I guess..


changed to for (i=numdon;i<numdon+don;i++) because I am using i to set the array value and i cannot overwrite any of the values in any arrays. I need to start off with the amount of donations already made(numdon-0 to begin with) and loop it how ever many times I want to make a donation (don). If a user wants to enter more donations after the loop is finished, the other values cannot be compromised.
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6048
  • View blog
  • Posts: 23,473
  • Joined: 23-August 08

Re: passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 09:57 AM

if (strcmp(temptype[i],dontype[n])== 0)


dontype is an array of characters. What does that make dontype[n]?


EDIT: Ignore this, I grabbed the wrong line of code.
Was This Post Helpful? 0
  • +
  • -

#7 bradleycmetz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-September 12

Re: passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 10:06 AM

View PostJackOfAllTrades, on 05 October 2012 - 09:57 AM, said:

if (strcmp(temptype[i],dontype[n])== 0)


dontype is an array of characters. What does that make dontype[n]?


I suppose that would make dontype[n] a single value? So maybe that means I need to compare the entire array and not just the value?

View Postbradleycmetz, on 05 October 2012 - 10:03 AM, said:

View PostJackOfAllTrades, on 05 October 2012 - 09:57 AM, said:

if (strcmp(temptype[i],dontype[n])== 0)


dontype is an array of characters. What does that make dontype[n]?


I suppose that would make dontype[n] an integer? So maybe that means I need to compare the entire array and not just the value?


wrong =/ I'm trying everything, no doubt about that. I'm very close to finding my answer.

This post has been edited by bradleycmetz: 05 October 2012 - 10:06 AM

Was This Post Helpful? 0
  • +
  • -

#8 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 10:06 AM

Also, dontype is a two dimensional array.
char dontype[100][20]

Figure that out in your code....

This post has been edited by AKMafia001: 05 October 2012 - 10:07 AM

Was This Post Helpful? 0
  • +
  • -

#9 bradleycmetz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-September 12

Re: passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 10:08 AM

View Postbradleycmetz, on 05 October 2012 - 10:06 AM, said:

View PostJackOfAllTrades, on 05 October 2012 - 09:57 AM, said:

if (strcmp(temptype[i],dontype[n])== 0)


dontype is an array of characters. What does that make dontype[n]?


I suppose that would make dontype[n] a single value? So maybe that means I need to compare the entire array and not just the value?

View Postbradleycmetz, on 05 October 2012 - 10:03 AM, said:

View PostJackOfAllTrades, on 05 October 2012 - 09:57 AM, said:

if (strcmp(temptype[i],dontype[n])== 0)


dontype is an array of characters. What does that make dontype[n]?


I suppose that would make dontype[n] an integer? So maybe that means I need to compare the entire array and not just the value?


wrong =/ I'm trying everything, no doubt about that. I'm very close to finding my answer.



Bah! So embarrassing. Whenever I reate a program for a long period of time, I end up switching things around and butchering everything. I didnt make the temptype array like I should have. Thanks for all the nudges in the right direction :)
Was This Post Helpful? 0
  • +
  • -

#10 Duta  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 21-June 12

Re: passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 10:34 AM

View Postbradleycmetz, on 05 October 2012 - 09:49 AM, said:

With all due respect I don't exactly know what you mean by pass to them.

Well, strcpy and strcmp are functions, and you are passing them values as parameters (or arguments, whichever you prefer to call them).
If I have the following:
int add(int aNumber, int anotherNumber)
{
    return aNumber + anotherNumber;
}

int main()
{
    int three = add(1, 2);
    return 0;
}


Then aNumber and anotherNumber are the function add's parameters. In main(), I pass add the values 1 and 2 (and then, of course, it returns their sum which gets assigned to three, but that's not the point here).

So... yeah. That's what I mean by passing.
Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6048
  • View blog
  • Posts: 23,473
  • Joined: 23-August 08

Re: passing arg 2 of `strcpy' makes pointer from integer without a cas

Posted 05 October 2012 - 10:34 AM

Sorry I led you down the wrong path by grabbing the wrong line from your code. I meant to grab

(strcpy(dontype[i],temptype[i]));

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1