-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall.html
More file actions
986 lines (800 loc) · 25.5 KB
/
all.html
File metadata and controls
986 lines (800 loc) · 25.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">
<title>Other Standard C Functions</title>
<link href="../cppreference.css" rel="stylesheet" type="text/css">
<link href="../prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../prettify.js"></script>
</head>
<body onload="prettyPrint()">
<table>
<tr>
<td>
<div class="body-content">
<div class="header-box">
<a href="../index-2.html">cppreference.com</a> > <a href=
"index.html">Other Standard C Functions</a>
</div>
<div class="name-format">
abort
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cstdlib>
void abort( void );
</pre>
<p>The function abort() terminates the current program. Depending on
the implementation, the return value can indicate failure.</p>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="assert.html">assert</a><br>
<a href="atexit.html">atexit</a><br>
<a href="exit.html">exit</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
assert
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cassert>
assert( exp );
</pre>
<p>The assert() macro is used to test for errors. If <em>exp</em>
evaluates to zero, assert() writes information to
<strong>stderr</strong> and exits the program. If the macro NDEBUG is
defined, the assert() macros will be ignored.</p>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="abort.html">abort</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
atexit
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cstdlib>
int atexit( void (*func)(void) );
</pre>
<p>The function atexit() causes the function pointed to by
<em>func</em> to be called when the program terminates. You can make
multiple calls to atexit() (at least 32, depending on your compiler)
and those functions will be called in reverse order of their
establishment. The return value of atexit() is zero upon success, and
non-zero on failure.</p>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="abort.html">abort</a><br>
<a href="exit.html">exit</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
bsearch
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cstdlib>
void *bsearch( const void *key, const void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) );
</pre>
<p>The bsearch() function searches <em>buf[0]</em> to
<em>buf[num-1]</em> for an item that matches <em>key</em>, using a
binary search. The function <em>compare</em> should return negative
if its first argument is less than its second, zero if equal, and
positive if greater. The items in the array <em>buf</em> should be in
ascending order. The return value of bsearch() is a pointer to the
matching item, or <strong>NULL</strong> if none is found.</p>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="qsort.html">qsort</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
exit
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cstdlib>
void exit( int exit_code );
</pre>
<p>The exit() function stops the program. <em>exit_code</em> is
passed on to be the return value of the program, where usually zero
indicates success and non-zero indicates an error.</p>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="abort.html">abort</a><br>
<a href="atexit.html">atexit</a><br>
<a href="system.html">system</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
getenv
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cstdlib>
char *getenv( const char *name );
</pre>
<p>The function getenv() returns environmental information associated
with <em>name</em>, and is very implementation dependent.
<strong>NULL</strong> is returned if no information about
<em>name</em> is available.</p>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="system.html">system</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
longjmp
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <csetjmp>
void longjmp( jmp_buf envbuf, int status );
</pre>
<p>The function longjmp() causes the program to start executing code
at the point of the last call to <a href="setjmp.html">setjmp</a>().
<em>envbuf</em> is usually set through a call to <a href=
"setjmp.html">setjmp</a>(). <em>status</em> becomes the return value
of <a href="setjmp.html">setjmp</a>() and can be used to figure out
where longjmp() came from. <em>status</em> should not be set to
zero.</p>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="setjmp.html">setjmp</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
qsort
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cstdlib>
void qsort( void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) );
</pre>
<p>The qsort() function sorts <em>buf</em> (which contains
<em>num</em> items, each of size <em>size</em>) using <a href=
"http://en.wikipedia.org/wiki/Quicksort">Quicksort</a>. The
<em>compare</em> function is used to compare the items in
<em>buf</em>. <em>compare</em> should return negative if the first
argument is less than the second, zero if they are equal, and
positive if the first argument is greater than the second. qsort()
sorts <em>buf</em> in ascending order.</p>
<div class="related-examples-format">
Example code:
</div>
<div class="related-examples">
<p>For example, the following bit of code uses qsort() to sort an
array of integers:</p>
<pre class="prettyprint">
int compare_ints( const void* a, const void* b ) {
int* arg1 = (int*) a;
int* arg2 = (int*) b;
if( *arg1 < *arg2 ) return -1;
else if( *arg1 == *arg2 ) return 0;
else return 1;
}
int array[] = { -2, 99, 0, -743, 2, 3, 4 };
int array_size = 7;
...
printf( "Before sorting: " );
for( int i = 0; i < array_size; i++ ) {
printf( "%d ", array[i] );
}
printf( "\n" );
qsort( array, array_size, sizeof(int), compare_ints );
printf( "After sorting: " );
for( int i = 0; i < array_size; i++ ) {
printf( "%d ", array[i] );
}
printf( "\n" );
</pre>
<p>When run, this code displays the following output:</p>
<pre class="prettyprint">
Before sorting: -2 99 0 -743 2 3 4
After sorting: -743 -2 0 2 3 4 99
</pre>
</div>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="bsearch.html">bsearch</a><br>
(C++ Algorithms) <a href="../cppalgorithm/sort.html">sort</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
raise
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <csignal>
int raise( int signal );
</pre>
<p>The raise() function sends the specified <em>signal</em> to the
program. Some signals:</p>
<table class="code-table">
<tr>
<th class="code-table-th">Signal</th>
<th class="code-table-th">Meaning</th>
</tr>
<tr>
<td class="code-table-td">SIGABRT</td>
<td class="code-table-td">Termination error</td>
</tr>
<tr>
<td class="code-table-td">SIGFPE</td>
<td class="code-table-td">Floating pointer error</td>
</tr>
<tr>
<td class="code-table-td">SIGILL</td>
<td class="code-table-td">Bad instruction</td>
</tr>
<tr>
<td class="code-table-td">SIGINT</td>
<td class="code-table-td">User presed CTRL-C</td>
</tr>
<tr>
<td class="code-table-td">SIGSEGV</td>
<td class="code-table-td">Illegal memory access</td>
</tr>
<tr>
<td class="code-table-td">SIGTERM</td>
<td class="code-table-td">Terminate program</td>
</tr>
</table>
<p>The return value is zero upon success, nonzero on failure.</p>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="signal.html">signal</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
rand
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cstdlib>
int rand( void );
</pre>
<p>The function rand() returns a pseudorandom integer between zero
and RAND_MAX. An example:</p>
<pre class="prettyprint">
srand( time(<strong>NULL</strong>) );
for( i = 0; i < 10; i++ )
printf( "Random number #%d: %d\n", i, rand() );
</pre>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="srand.html">srand</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
setjmp
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <csetjmp>
int setjmp( jmp_buf envbuf );
</pre>
<p>The setjmp() function saves the system stack in <em>envbuf</em>
for use by a later call to <a href="longjmp.html">longjmp</a>(). When
you first call setjmp(), its return value is zero. Later, when you
call <a href="longjmp.html">longjmp</a>(), the second argument of
<a href="longjmp.html">longjmp</a>() is what the return value of
setjmp() will be. Confused? Read about <a href=
"longjmp.html">longjmp</a>().</p>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="longjmp.html">longjmp</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
signal
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <csignal>
void ( *signal( int signal, void (* func) (int)) ) (int);
</pre>
<p>The signal() function sets <em>func</em> to be called when
<em>signal</em> is recieved by your program. <em>func</em> can be a
custom signal handler, or one of these macros (defined in
the csignal header file):</p>
<table class="code-table">
<tr>
<th class="code-table-th">Macro</th>
<th class="code-table-th">Explanation</th>
</tr>
<tr>
<td class="code-table-td">SIG_DFL</td>
<td class="code-table-td">default signal handling</td>
</tr>
<tr>
<td class="code-table-td">SIG_IGN</td>
<td class="code-table-td">ignore the signal</td>
</tr>
</table>
<p>Some basic signals that you can attach a signal handler to
are:</p>
<table class="code-table">
<tr>
<th class="code-table-th">Signal</th>
<th class="code-table-th">Description</th>
</tr>
<tr>
<td class="code-table-td">SIGTERM</td>
<td class="code-table-td">Generic stop signal that can be
caught.</td>
</tr>
<tr>
<td class="code-table-td">SIGINT</td>
<td class="code-table-td">Interrupt program, normally
ctrl-c.</td>
</tr>
<tr>
<td class="code-table-td">SIGQUIT</td>
<td class="code-table-td">Interrupt program, similar to
SIGINT.</td>
</tr>
<tr>
<td class="code-table-td">SIGKILL</td>
<td class="code-table-td">Stops the program. Cannot be
caught.</td>
</tr>
<tr>
<td class="code-table-td">SIGHUP</td>
<td class="code-table-td">Reports a disconnected terminal.</td>
</tr>
</table>
<p>The return value of signal() is the address of the previously
defined function for this signal, or SIG_ERR is there is an
error.</p>
<div class="related-examples-format">
Example code:
</div>
<div class="related-examples">
<p>The following example uses the signal() function to call an
arbitrary number of functions when the user aborts the program. The
functions are stored in a vector, and a single "clean-up"
function calls each function in that vector of functions when the
program is aborted:</p>
<pre class="prettyprint">
void f1() {
cout << "calling f1()..." << endl;
}
void f2() {
cout << "calling f2()..." << endl;
}
typedef void(*endFunc)(void);
vector<endFunc> endFuncs;
void cleanUp( int dummy ) {
for( unsigned int i = 0; i < endFuncs.size(); i++ ) {
endFunc f = endFuncs.at(i);
(*f)();
}
exit(-1);
}
int main() {
// connect various signals to our clean-up function
signal( SIGTERM, cleanUp );
signal( SIGINT, cleanUp );
signal( SIGQUIT, cleanUp );
signal( SIGHUP, cleanUp );
// add two specific clean-up functions to a list of functions
endFuncs.push_back( f1 );
endFuncs.push_back( f2 );
// loop until the user breaks
while( 1 );
return 0;
}
</pre>
</div>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="raise.html">raise</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
srand
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cstdlib>
void srand( unsigned seed );
</pre>
<p>The function srand() is used to seed the random sequence generated
by <a href="rand.html">rand</a>(). For any given <em>seed</em>,
rand() will generate a specific "random" sequence over and
over again.</p>
<pre class="prettyprint">
srand( time(<strong>NULL</strong>) );
for( i = 0; i < 10; i++ )
printf( "Random number #%d: %d\n", i, rand() );
</pre>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="rand.html">rand</a><br>
(Standard C Date & Time) <a href=
"../stddate/time.html">time</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
system
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cstdlib>
int system( const char *command );
</pre>
<p>The system() function runs the given <em>command</em> by passing
it to the default command interpreter.</p>
<p>The return value is usually zero if the command executed without
errors. If <em>command</em> is <strong>NULL</strong>, system() will
test to see if there is a command interpreter available. Non-zero
will be returned if there is a command interpreter available, zero
if not.</p>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
<a href="exit.html">exit</a><br>
<a href="getenv.html">getenv</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
<div class="name-format">
va_arg
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <cstdarg>
type va_arg( <strong>va_list</strong> argptr, type );
void va_end( <strong>va_list</strong> argptr );
void va_start( <strong>va_list</strong> argptr, last_parm );
</pre>
<p>The va_arg() macros are used to pass a variable number of
arguments to a function.</p>
<ol>
<li>First, you must have a call to va_start() passing a valid
<strong>va_list</strong> and the mandatory first argument of the
function. This first argument can be anything; one way to use it is
to have it be an integer describing the number of parameters being
passed.</li>
<li>Next, you call va_arg() passing the <strong>va_list</strong>
and the type of the argument to be returned. The return value of
va_arg() is the current parameter.</li>
<li>Repeat calls to va_arg() for however many arguments you
have.</li>
<li>Finally, a call to va_end() passing the
<strong>va_list</strong> is necessary for proper cleanup.</li>
</ol>
<p>For example:</p>
<pre class="prettyprint">
int sum( int num, ... ) {
int answer = 0;
<strong>va_list</strong> argptr;
va_start( argptr, num );
for( ; num > 0; num-- ) {
answer += va_arg( argptr, int );
}
va_end( argptr );
return( answer );
}
int main( void ) {
int answer = sum( 4, 4, 3, 2, 1 );
printf( "The answer is %d\n", answer );
return( 0 );
}
</pre>
<p>This code displays 10, which is 4+3+2+1.</p>
<p>Here is another example of variable argument function, which is a
simple printing function:</p>
<pre class="prettyprint">
void my_printf( char *format, ... ) {
<strong>va_list</strong> argptr;
va_start( argptr, format );
while( *format != '\0' ) {
// string
if( *format == 's' ) {
char* s = va_arg( argptr, char * );
printf( "Printing a string: %s\n", s );
}
// character
else if( *format == 'c' ) {
char c = (char) va_arg( argptr, int );
printf( "Printing a character: %c\n", c );
break;
}
// integer
else if( *format == 'd' ) {
int d = va_arg( argptr, int );
printf( "Printing an integer: %d\n", d );
}
*format++;
}
va_end( argptr );
}
int main( void ) {
my_printf( "sdc", "This is a string", 29, 'X' );
return( 0 );
}
</pre>
<p>This code displays the following output when run:</p>
<pre class="prettyprint">
Printing a string: This is a string
Printing an integer: 29
Printing a character: X
</pre>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>
<hr>
</body>
<!-- Mirrored from cppreference.com/stdother/all.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:25 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>