Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# CSCI136part2
# CSCI136part2
## Forked by Anthony
### Observations Here
### Commented in code

1. Has uses namespace std, MZ disapproves.
2. File funcs.cpp consists of removeLeadingSpaces and countChar.
3. Tried to stream input from text file. Unsucessful in current iteration.
4. Does not contain unindent or indent functions.
5. Functions work.
6. Added unindent and indent functions.
34 changes: 32 additions & 2 deletions lab_08/funcs.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
#include <iostream>
#include <cctype>

//using a namespace
using namespace std;


string removeLeadingSpaces(string line){

//counter
int i=0;

//while loop to find first !space
while(isspace(line[i])){
i++;
}

//returns line without leading spaces
return line.substr(i,line.length()-i);
}

int countChar(string line, char c){

//counter
int o = 0;

//for loops to find matches to c, adding to o every time matched
for(int i=0; i<line.length(); i++){
if(line[i]==c){
o++;
Expand All @@ -22,6 +32,26 @@ int countChar(string line, char c){
return o;
}

string unindent(std::string line){
string result;
result += removeLeadingSpaces(line) + "\n";
return result;

string indent(){
int tabs = 0;
string result;
string line;
while (getline(cin, line)){
line = unindent(line);
tabs -= countChar(line, '}');
for (int i = 0; i < tabs; i++){
result += "\t";
}
}
return result;
}

//Trying to read from a file to test? I only inputted from the terminal
/*
int main(){

Expand All @@ -42,4 +72,4 @@ int main(){

cout << indent << endl;
}
*/
*/
8 changes: 8 additions & 0 deletions lab_08/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
int main(){
// Hi, I'm a program!
int x = 1;
for(int i = 0; i < 10; i++) {
cout << i;
cout << endl;
}
}