How do i skip a character ?

Hi Guys

I have two questions;
(1)how do i skip an unwanted character while reading from a file ?
(2) how to i limit the number of characters i want to extract while reading from a file.

Thanks

1
2
  
Maybe you could give some example(s) of the contents of the file and the types of problems you need to solve in terms of how your program should interpret the data. e.g. is it numbers or strings or individual characters ...
Last edited on
from this input of employee names

SS van der Merwe;PJ Ferreira;HW du Plessis;DF Kodisang;

i need to extract only the first 8 characters of each employee name which is seperted by a semi colon. i must exclude any whitespaces and alphanumeric characters.

so the output must be

ssSSvander;PJFerrei;HWduPles;DFKodisa;

use... if ?
herewith the code

its not picking up nor skipping

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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include<cctype>
using namespace std;

int main()
{
    ifstream fin;
    fin.open("EmployeeNames.txt");
    if(fin.fail())
    {
        cout<<" Error in opening Input file...."<<endl;
        exit(1);
    }
    else
    {
        cout<<" Opening Input file ..."<<endl;
        cout<<" Reading from Input file ... please wait... "<<endl;
    }

    ofstream fout;
    fout.open("EmailIDs.txt");//ios::app)
    if (fout.fail())
    {
        cout<<"Error in creating output file..."<<endl;
        exit(1);
    }
    else
    {
        cout<<" Creating Email IDs from employee names....please wait..."<<endl;
        cout<<endl;
    }

char nextSymbol,semiColon = ';';

int noOfEmployees = 0, count = 0, noOfEmailIDs = 0 ;

const int limit = 8;

while( fin>>nextSymbol)

{

            if (count == limit)
               {
                cout<<";";
                fout.put(semiColon);
                noOfEmailIDs++;
               }
            else
                {
                fin>>nextSymbol;
                }
}

                 if(nextSymbol != semiColon)
                {
                    count = 0;
                    fin>>nextSymbol;
                }
                else
                {
                    count = 0;
                    fin>>nextSymbol;
                    fout.put(nextSymbol);
                    count++;
                }

                if(nextSymbol == semiColon)
                {

                count = 0;
                noOfEmployees++;
                fin>>nextSymbol;
                fin.put(nextsymbol);
                count++;

                }
                else
                {

                }

    if ( isalpha(nextSymbol) || isspace(nextSymbol) || isdigit(nextSymbol) ) // checking if next char is an empty space or alphanumeric
    {

            fin>>nextSymbol;                //skip it and move to the next ensuring limit of 8 characteres is maintained
           count -= 1;
                                            //copy the next symbol that is not alphanumeric or a space
    }

   else
   {

   }
  //  count++;

    fin.close();
    fout.close();
    return 0;

}
Topic archived. No new replies allowed.