main
test-branch
| Line | |
|---|
| 1 | /* This file is to demonstrate the file I/O function fscanf.
|
|---|
| 2 | * A file has unconstrained length by default. If you want to
|
|---|
| 3 | * specify the length of a file, you need to use the system
|
|---|
| 4 | * function $textFileLength() provided by civl-stdio.cvh.
|
|---|
| 5 | *
|
|---|
| 6 | * This program has no violation.
|
|---|
| 7 | */
|
|---|
| 8 | #include<civlc.cvh>
|
|---|
| 9 | #include<stdio.h>
|
|---|
| 10 | #include<civl-stdio.cvh>
|
|---|
| 11 |
|
|---|
| 12 | int fooLength = $text_file_length("foo");
|
|---|
| 13 |
|
|---|
| 14 | $assume(fooLength == 5);
|
|---|
| 15 |
|
|---|
| 16 | void main(){
|
|---|
| 17 | FILE *file = fopen("foo", "r");
|
|---|
| 18 | int a[5];
|
|---|
| 19 | int i = 0;
|
|---|
| 20 |
|
|---|
| 21 | while($true){
|
|---|
| 22 | int count = fscanf(file, "%d", &a[i]);
|
|---|
| 23 |
|
|---|
| 24 | if(count == EOF)
|
|---|
| 25 | break;
|
|---|
| 26 | i++;
|
|---|
| 27 | }
|
|---|
| 28 | $free(file);
|
|---|
| 29 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.