strncpy(ver, buffer2 +5,2);


 
Thread Tools Search this Thread
Top Forums Programming strncpy(ver, buffer2 +5,2);
# 1  
Old 09-13-2005
strncpy(ver, buffer2 +5,2);

Hi,
Can someone help me understand this code?
strncpy(job, buffer2,5);
strncpy(ver, buffer2 +5,2);

Thanks for all the help!
# 2  
Old 09-13-2005
Quote:
Originally Posted by whatisthis
Hi,
Can someone help me understand this code?
If we start with this:
Code:
char buffer2[]="abcdeFGH";
char job[6];
char ver[3];

then, strncpy(job, buffer2,5); will copy the first 5 characters of buffer2 into job, i.e. "abcde". It will NOT null-terminate it, though. strncpy doesn't NULL-terminate the destination string unless it actually finds the NULL terminator.

Note that buffer2 is an array, and adding an offset to an array moves you farther down that array. So buffer2+5 moves it 5 down, to the"FGH" part. So, strncpy(ver, buffer2 +5,2); will copy 2 characters of "FGH" into ver, but again, doesn't NULL terminate it because it didn't find the NULL terminator.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. HP-UX

GCC ver 3.4.6

anyone has an idea from where can i download gcc 3.4.6 for hp-ux 11iv3 itanium? (0 Replies)
Discussion started by: guy3145
0 Replies

2. UNIX for Dummies Questions & Answers

Question on Redhat ver.6 RPM's

Hi, Using Redhat version 6.0, I need nmap so I have downloaded. But it requires many other dependencies, when I try to install it. See below err.msg. Is there any other way to get this installed, or I need to download each of the dependencies. rpm -Uhv nmap-5.51-2-mdv2011.0.x86_64.rpm... (3 Replies)
Discussion started by: samnyc
3 Replies

3. Solaris

SOLARIS/BEA WEBLOGIC ver.8.1

Hello all, I am having a little issue with BEA webloigc server Version 8.1, previously, we we confugred we where able to Grep processes for BEA and we could get the processes listed now I am only able to see the start weblogic script process. the weblogic server is up and running and performing its... (2 Replies)
Discussion started by: jvgvr6
2 Replies

4. Programming

Reg: strncpy function

Hi All, Please clear the following doubt. int main() { char str1; char str2 = "HelloWorld"; int len = strlen(str2); strncpy(str1, str2, len); str1 = '\0'; printf("%s", str1); } In the above program i'm initializing the 10th byte of str1 to null. what will happen to the memory of... (13 Replies)
Discussion started by: arunviswanath
13 Replies

5. UNIX for Dummies Questions & Answers

USB support in what ver. HP-UX

Can someone clue me in as to what version of HP-UX did USB support start? Specifically mass storage support. We have serveral HP Visualize systems and would like to connect up an external USB drive to do backups. (0 Replies)
Discussion started by: emcatc
0 Replies

6. Programming

Strncpy - coredump

haiu all what makes strncpy to coredump (0 Replies)
Discussion started by: vijaysabari
0 Replies

7. UNIX for Advanced & Expert Users

X25 on Tru UNIX ver 5

How do i set up X25 protocol on version 5 of Tru Unix (Compaq). I have manged to do it using version 4. What are the major differences.:confused: (1 Reply)
Discussion started by: samudimu
1 Replies

8. AIX

New IBM AIX 5L ver 5.1 .. any thoughts?

I read that IBM came up with a new AIX version that would be fully integrated with Linux (I guess compared to older versions of AIX that could not) and I was hoping I bring this for discussion here so I learn more about IBM UNIX OS Can anybody put few simple and practical comparisons between... (0 Replies)
Discussion started by: aliissa
0 Replies

9. Cybersecurity

BIND Ver. 8

Hi everyone I'm a HPUX system admin, and need some help. Our organisation is full of red tape and managers like that like to hold many meetings but take little action. I need to persuade my line manager that we should move our two nameservers onto BIND 8. Can anyone please point me to some... (2 Replies)
Discussion started by: alwayslearningunix
2 Replies
Login or Register to Ask a Question