Sponsored Content
Full Discussion: Problem with Sprintf
Top Forums Programming Problem with Sprintf Post 302464674 by Corona688 on Wednesday 20th of October 2010 05:22:25 PM
Old 10-20-2010
Quote:
Originally Posted by DGPickett
PS: I usually pass 'char *x' not 'char x[]' as it is more truthful and you should not be moving arrays by value!
It's passed by reference either way.
Code:
#include <stdio.h>

void function(char arr[60])
{
        printf("arr=%p\n", arr);
}

int main(void)
{
        char buf[60];

        printf("buf=%p\n", buf);
        function(buf);
}

Code:
 $ ./a.out
buf=0xbf8d06c8
arr=0xbf8d06c8
$

All giving a function parameter an array type does is stop code in the function from modifying the pointer value. Considering making a pointer copy they can modify is the first thing done in this function though, they might as well make it a pointer and be done with it.
 

10 More Discussions You Might Find Interesting

1. Solaris

problem with sprintf snprintf in Solaris

******************************** Following is not the real issue. The issue is with popen. Plz continue forward with the thread to get a better picture. ******************************** Hi, I am working on a customised ftp application. In it we have used sprintf to store a UNIX command... (7 Replies)
Discussion started by: diganta
7 Replies

2. Programming

sprintf function

Hi, Can someone help me to figure out whether this code is to write file to /tmp/TIMECLOCK directory or just to asign a variable with "/tmp/TIMECLOCK/name.log_copy.pid" as the string? I am looking into an old C program and could not figure out where in the code that creates... (1 Reply)
Discussion started by: whatisthis
1 Replies

3. Shell Programming and Scripting

ksh scripting sprintf

is there any sprintf function in korn shell scripting, or anything similar to sprintf? (2 Replies)
Discussion started by: gfhgfnhhn
2 Replies

4. Programming

equivalent of sprintf in C++

Hi My requirement is to convert the following to C++ char buffer; sprintf(buffer,"%s %-50s %6s %-6d %s\n",a.substr(0,5),a.substr(10,20)) Since the buffer is of varying length, i cannot hardcode the value as 90. i would like to convert the buffer to string object so that it can receive any... (1 Reply)
Discussion started by: dhanamurthy
1 Replies

5. Shell Programming and Scripting

sprintf result on perl

Hello, In perl lang, I have create a string (@str) by sprintf but unfortunately when program printed it out, only I could saw a number like 1. Certainly printf doesn't problem. How I can convert a string that are result of sprintf to a common string format??! Thanks in advance. PLEASE HELP ME. (2 Replies)
Discussion started by: Zaxon
2 Replies

6. Shell Programming and Scripting

printf vs sprintf - perl

I would like to assign the output of printf to a variable in perl , it give me back a "1" instead of the time. How can I stuff the variable with what printf returns? Here is my code: #!/usr/bin/perl $time = localtime(time);... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

7. Shell Programming and Scripting

Detect sprintf and fprintf bad use

Hello again, I don't know about regexp so I throw this question here: How can I detect files where, for example: sprintf (var1, "hello %s %s", sub1); The problem here is that we have 2 %s and only a variable. Or... the inverse: sprintf (var1, "hello %s %s", sub1, sub2, sub3,...subn); ... (2 Replies)
Discussion started by: albertogarcia
2 Replies

8. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

9. Programming

How to right pad with zeros using sprintf?

I need to right-pad with zeros a string by using (s)printf. I looked up the manual and tried with printf("%-19s", buffer); which right-pad the string with spaces. So I tried printf("%019s", buffer); which left-pad the string with zeros. So I tried both printf("%-019s", buffer);... (9 Replies)
Discussion started by: emitrax
9 Replies

10. UNIX for Dummies Questions & Answers

Join with awk using sprintf

Hi, Trying to join 2 files with awk (file1 has variable number of fields; file 2 has constant number of fields) file1: hook1|AA|BB|CC|DD hook2|EE|FF file2: hook1|11|22 hook2|33|44 hook3|55|66 output: hook1|11|22|AA|BB|CC|DD hook2|33|44|EE|FF hook3|55|66 What I tried so far:... (3 Replies)
Discussion started by: beca123456
3 Replies
CheckDigits::M10_010(3pm)				User Contributed Perl Documentation				 CheckDigits::M10_010(3pm)

NAME
CheckDigits::M10_010 - compute check digits for Postscheckkonti (CH) SYNOPSIS
use Algorithm::CheckDigits; $pck = CheckDigits('postcheckkonti'); if ($pck->is_valid('85-12345678-7')) { # do something } $cn = $pck->complete('85-12345678'); # $cn = '85-12345678-7' $cd = $pck->checkdigit('85-12345678-7'); # $cd = '7' $bn = $pck->basenumber('85-12345678-7'); # $bn = '85-12345678' DESCRIPTION
ALGORITHM 1. The sequence of digits is processed left to right. For the first digit we assume a carry forward of 0. 2. For each digit d(i) the carry forward cf(i) is the digit at the the position p in the sequence ( 0, 9, 4, 6, 8, 2, 7, 1, 3, 5 ), where p is (d(i) + cf(i-1)) modulo 10. 3. The check digit is the difference of the sum from step 3 to the next multiple of 10. METHODS is_valid($number) Returns true only if $number consists solely of numbers and the last digit is a valid check digit according to the algorithm given above. Returns false otherwise, complete($number) The check digit for $number is computed and concatenated to the end of $number. Returns the complete number with check digit or '' if $number does not consist solely of digits and spaces. basenumber($number) Returns the basenumber of $number if $number has a valid check digit. Return '' otherwise. checkdigit($number) Returns the checkdigit of $number if $number has a valid check digit. Return '' otherwise. EXPORT None by default. AUTHOR
Mathias Weidner, <mathias@weidner.in-bad-schmiedeberg.de> SEE ALSO
perl, CheckDigits, www.pruefziffernberechnung.de. perl v5.10.0 2008-05-17 CheckDigits::M10_010(3pm)
All times are GMT -4. The time now is 09:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy