for clarity and legibility I was trying to just utilize it as a separate function.
But it is a seperate function. I don't understand.
If you don't care about thread safety, you could use a global variable (or a static, local variable) and return an "int *". But this isn't reccomended because it's not threadsafe. When you look for examples of how it's done in system libraries, you see all sorts of things like sprintf(), fgets() and the like which all take buffers you give them. And the ones which don't, like gets(), are much maligned.
Like you said, it is a separate function, but I need to utilize it so that it returns the array that the user typed in. I don't want a simple true or false to be returned because that is not what I'm doing. I know I use the word "password" but it's more so a code. I'll try to give a basic idea of what my program does. I'll just pseudo code it.
As you can see, I use codemaker[] throughout the program and I need it to be set to the array that is created in read_unbuffered.
Let me make sure I understand everything correctly first. When you have variables within a function, they are local to that function correct? It will not have any affect on the variables within the main, right? So in my read_unbuffered() I'm using password[] and in my main I'm using codeMaker[]. These have no bearing on each other right?
So if I want to alter codeMaker (located in main()) with the function read_unbuffered I should not use a pointer?
Here's an excerpt from my main:
And, just to refresh, here is the function:
As you can see, I've changed the name of read_unbuffered() to getcode(). Also in getcode() I changed the array from password[] to codeMaker[] in attempt to make this work.
So, since the codeMaker[] in getcode() is local to getcode(), it is not affecting the codeMaker[] in main(), right? Which means, when I check for validity in main() it is checking a different codeMaker[] that it needs to be checking.
So if I want to alter codeMaker (located in main()) with the function read_unbuffered I should not use a pointer?
That's the precise opposite of what I just told you. You're confusing yourself with too much doublethink.
Pass a pointer to codeMaker into read_unbuffered. Just like the way dozens of stdio functions take a pointer to a buffer, to let them read or write to that buffer. That tells it what memory it should modify, so it can modify the contents of that array directly without passing anything back (because returning an array is nonsensical, and returning a pointer doesn't modify its contents, so both are useless in this context). As long as the memory's valid, a pointer to memory doesn't care about variable scope.
Quote:
So, since the codeMaker[] in getcode() is local to getcode(), it is not affecting the codeMaker[] in main(), right?
Correct. It bears no resemblance to the example I showed you, however, which does modify variables outside itself. I'll flesh it out a little more.
Last edited by Corona688; 12-23-2010 at 01:28 PM..
My file "test.dat" data as below
Requirement is to mask(replace) all english characters with "X" EXCEPT first 7 characters of every line.
my command
awk '{gsub("]","X")}1' test.dat
looks not working properly, Appreciate any suggestion... (6 Replies)
I have a requirement of masking few specific fields in the UNIX file. The details are as following-
File is fixed length file with each record of 250 charater length.
2 fields needs to be masked – the positions are 21:30 and 110:120
The character by character making needs to be done which... (5 Replies)
Is there a way to mask the password inside of a script to minimize the impact of a comprimised server? So
ssh -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l testuser 192.168.3.1 "mysqldump --opt --all-databases -u root -pPassword| gzip" > $backup_dir/mysqldump.gz
a... (2 Replies)
Hi I am facing an issue with the below script which has the below line
each field being separated with a tab.
I need to mask the 8 and 7th field based on following conditions
1. 8th field is 16 in length and is numerics
i will mask the middle 6 digits except the first 6 and last 4.
input... (2 Replies)
Hi,
I currently have a UNIX script with a function that uses a username and password to connect to the database, retrieve some information and then exit.
At the moment, am getting the username and password from a hidden plain text file and permission set to -r--------, i.e. read only to who... (1 Reply)
I have a pipe delimited file that I need to 'mask' to before loading to keep some data confidential. I need to maintain the first 4 bytes of certain columns and replace the remaining bytes with an 'x'. I would like to maintain spaces but it's not a requirement.
Example, need to mask columns 2... (2 Replies)
Hello,
I need to know that whether a content of a string can be hidden or masked inside a shell script.
My Sample Code is given below
<Code>
#!/usr/bin/ksh
Userid=test
DB=temp
Passwd=`java Decryption test`
# The Above command will get the encryped password for "test" user id and store... (2 Replies)
Is it possible for a internal LAN to mask a IP e.g. i have a server ip running the intranet ip being 192.168.0.8 and i want to make that like www.intranet.com is this possible on a internal network ? (1 Reply)