Yurttas/PL/OOL/Cplusplus/F/06/02/02/get string values.cpp

From ZCubes Wiki
Revision as of 23:55, 6 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="cpp" line start="1" enclose="div">/* Copyright(C) 1998 All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc.. P...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
 1/*
 2   Copyright(C) 1998
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4   
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : January 1, 1998.
11   author : Salih Yurttas.
12
13   get_string_values.cpp
14*/
15
16
17#include <iostream>
18
19#include <fstream>
20
21#include <memory>
22
23using namespace std;
24
25const int MAX_SIZE_STRING=32;
26
27int get_string_values(char* v[]) {
28  char filename[MAX_SIZE_STRING];
29  int i;
30
31  cout << "--> input filename : ";
32  cin >> filename;
33  cout << endl;
34
35  ifstream f_in(filename);
36
37  if(!f_in) {
38    cerr << "File named as " << filename << " is not opened for input." << endl;
39    exit(1);
40  }
41  else {
42    i = 0;
43    do {
44      v[i] = (char *) calloc(MAX_SIZE_STRING, sizeof(char));
45    } while(f_in>>v[i++]);
46  }
47
48  f_in.close();
49
50  return --i; /* number of input values counted. */
51}