Sponsored Content
Top Forums Shell Programming and Scripting Passing argument 1 of 'scanf' makes po Post 302854169 by sgradywhite on Monday 16th of September 2013 10:29:15 PM
Old 09-16-2013
ok when I try to enter the value that is suppose to be found in Array B but the output says it was in Array A

Code:
#include "stdio.h" 
02#define MAXARRAY 12 
03#define MAXARRAY1 6 
04#define MAXARRAY2 9 
05  
06int main() 
07{ 
08        int a[MAXARRAY]; 
09        int b[MAXARRAY1]; 
10        int c[MAXARRAY2]; 
11        int nvals; 
12        int nvals1; 
13        int nvals2; 
14        int size =0; 
15        int fetch; 
16        size = sizeof(a)/sizeof(a[0]); 
17        printf("Array A has %d elements\n ", size); 
18        int size1=0; 
19         
20     
21        size1 = sizeof(B)/>/sizeof(b[0]); 
22        printf("Array B has %d elements\n ", size1); 
23        int size2=0; 
24        size2 = sizeof(c)/sizeof(c[0]); 
25        printf("Array C has %d elements\n " , size2); 
26        printf("Input the values in Array A\n "); 
27        nvals = get_data(a,MAXARRAY); 
28        printf("Input the values in Array B \n"); 
29        nvals1 = get_data(b, MAXARRAY1); 
30        printf("Input the values in Array C \n"); 
31        nvals2 = get_data(c, MAXARRAY2); 
32        int value; 
33        printf("Enter the value you wish to find in THREE arrays of floats"); 
34        scanf("%d", &value); 
35        fetch=find_value(&a,&size,value); 
36  
37        if (find_value(&a,&size, value) == 0) 
38        { 
39        printf("The value is found in Array A!"); 
40        } 
41        else
42        { 
43                fetch=find_value(&b, &size1, value); 
44  
45                 if (find_value(&b, &size1, value) == 0 ) 
46                { 
47                printf("The value is found in Array B!"); 
48                } 
49                else
50                { 
51                        fetch= find_value(&c, &size2, value); 
52  
53                         if (find_value(&c, &size2, value) == 0) 
54                        { 
55                         
56                                                                                                        
57  
58                        printf("The value is found in Array C!"); 
59                        } 
60                        else
61                        { 
62                        printf("The value is not found in Three Arrays!"); 
63                        } 
64                } 
65        } 
66} 
67  
68int get_data(int vals[],int max) 
69{ 
70        int n = 0; 
71  
72        while (n < max && scanf("%d", &vals[n]) == 1) 
73        n++; 
74        return n; 
75} 
76  
77int find_value(int *array[] ,int *scale,int num) 
78{ 
79        int i; 
80  
81  
82        for (i = *scale -1; i>= 0; i--) 
83        {       if ( *array[i]==num ); 
84                { 
85                return 0; 
86                } 
87        } 
88  
89                return (-1); 
90  
91}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing argument into awk

i'm trying to pass a numerical argument with function xyz to print specfic lines of filename, but my 'awk' syntax is incorrect. ie xyx 3 (prints the 3rd line, separated by ':' of filename) function xyz() { arg1=$1 cat filename | awk -F: -v x=$arg1 '{print $x}' } any ideas? (4 Replies)
Discussion started by: prkfriryce
4 Replies

2. Shell Programming and Scripting

passing Argument

Hi All, i have script like below.. echo "1) first option" echo "" echo "2) second option" echo "" echo "*) please enter the correct option" read select case $select in 1) echo "first option selected" ;; 2) echo "second option selected" ;; *) echo "please enter the correct... (4 Replies)
Discussion started by: Shahul
4 Replies

3. UNIX for Dummies Questions & Answers

Using * when passing argument to alias

I have some folders with this structure: /data/me/a123xxx Where "xxx" is some changing series of letters, and "123" changes so folders might look like: /data/me/a123xxx /data/me/a234ysd /data/me/a534sds etc. The numbers are what matter to me (they identify the folder), so I created an... (7 Replies)
Discussion started by: ramparts
7 Replies

4. Shell Programming and Scripting

Passing argument to nawk

Hi all I have got a file digits.data containing the following data 1 3 4 2 4 9 7 3 1 7 3 10 I am writing a script that will pass an argument from C-shell to nawk command. But it seems the values in the nawk comman does not get set. the program does not print no values out. Here is the... (2 Replies)
Discussion started by: ganiel24
2 Replies

5. Programming

warning: passing arg 1 of `inet_addr' makes pointer from integer without a cast

I use solaris10,following is tcp client code: #include "cliserv.h" int main(int argc,char argv){ struct sockaddr_in serv; char request,reply; int sockfd,n; if(argc!=2) err_quit("usage: tcpclient <IP address of server>"); if((sockfd=socket(PF_INET,SOCK_STREAM,0))<0) ... (1 Reply)
Discussion started by: konvalo
1 Replies

6. Shell Programming and Scripting

passing argument from one function to another

Hi all, In the given script code . I want to pass the maximum value that variable "i" will have in function DivideJobs () to variable $max of function SubmitCondorJob(). Any help? Thanks #!/bin/bash ... (55 Replies)
Discussion started by: nrjrasaxena
55 Replies

7. Shell Programming and Scripting

passing argument in script?

hi, I want to implement some function to perform following task if ; then $TEXT = "Data_0" else $TEXT = $1 fi if ; then $Lines = 45 else $Lines = $2 fi Kindly suggest, thanks (11 Replies)
Discussion started by: nrjrasaxena
11 Replies

8. Shell Programming and Scripting

Help with passing argument

Hi, I have a script that is scheduled with cron and runs every night. The cron part looks like this: 00 20 * * 0,1,2,3,4,5,6 /usr/local/bin/BACKUP TBTARM HOT DELETE My issue is with the 3rd parameter. Somewhere in the script, i want to tell the script to delete some files if the 3rd... (7 Replies)
Discussion started by: dollypee
7 Replies

9. Shell Programming and Scripting

Argument passing

How to pass the alphabet character as a argument in case and in if block? ex: c=$1 if a-z ]] then echo "alphabet" case $1 in a-z) echo "the value is a alphabet" edit by bakunin: please use CODE-tags. We REALLY mean it. (9 Replies)
Discussion started by: Roozo
9 Replies

10. UNIX for Beginners Questions & Answers

Passing a second argument

I am trying to pass a second argument like so: if ] then export ARG2=$2 else message "Second argument not specified: USAGE - $PROGRAM_NAME ARG1 ARG2" checkerror -e 2 -m "Please specify if it is a history or weekly (H or W) extract in the 2nd argument" fi however, it always goes... (4 Replies)
Discussion started by: MIA651
4 Replies
MooseX::AttributeHelpers::Trait::Collection::Array(3pm) User Contributed Perl DocumentationMooseX::AttributeHelpers::Trait::Collection::Array(3pm)

NAME
MooseX::AttributeHelpers::Collection::Array - Array attribute SYNOPSIS
package Stuff; use Moose; use MooseX::AttributeHelpers; has 'options' => ( metaclass => 'Collection::Array', is => 'ro', isa => 'ArrayRef[Int]', default => sub { [] }, provides => { 'push' => 'add_options', 'pop' => 'remove_last_option', } ); DESCRIPTION
This module provides an Array attribute which provides a number of array operations. See MooseX::AttributeHelpers::MethodProvider::Array for more details. METHODS
meta method_provider has_method_provider helper_type BUGS
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. AUTHOR
Stevan Little <stevan@iinteractive.com> COPYRIGHT AND LICENSE
Copyright 2007-2009 by Infinity Interactive, Inc. <http://www.iinteractive.com> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-01-02 MooseX::AttributeHelpers::Trait::Collection::Array(3pm)
All times are GMT -4. The time now is 11:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy