Update progress to 1-21
This commit is contained in:
parent
bf8636944c
commit
2a678c087a
|
@ -15,6 +15,9 @@ Extra Arguments=
|
|||
Install Directory=
|
||||
Runtime=Host System
|
||||
|
||||
[Clazy]
|
||||
checks=level2
|
||||
|
||||
[Cppcheck]
|
||||
checkPerformance=true
|
||||
checkPortability=true
|
||||
|
@ -26,9 +29,38 @@ Launch Configurations=Launch Configuration 0
|
|||
[Launch][Launch Configuration 0]
|
||||
Configured Launch Modes=execute
|
||||
Configured Launchers=nativeAppLauncher
|
||||
Name=New Compiled Binary Launcher
|
||||
Name=main
|
||||
Type=Native Application
|
||||
|
||||
[Launch][Launch Configuration 0][Data]
|
||||
Arguments=
|
||||
Break on Start=false
|
||||
Debugger Shell=
|
||||
Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00)
|
||||
Dependency Action=Nothing
|
||||
Display Demangle Names=true
|
||||
Display Static Members=false
|
||||
EnvironmentGroup=
|
||||
Executable=file:///home/caskd/Projects/LearningC
|
||||
External Terminal=konsole --noclose --workdir %workdir -e %exe
|
||||
GDB Path=
|
||||
LLDB Arguments=
|
||||
LLDB Config Script=
|
||||
LLDB Environment=
|
||||
LLDB Executable=
|
||||
LLDB Inherit System Env=true
|
||||
LLDB Remote Debugging=false
|
||||
LLDB Remote Path=
|
||||
LLDB Remote Server=
|
||||
Project Target=LearningC,learningc
|
||||
Remote GDB Config Script=
|
||||
Remote GDB Run Script=
|
||||
Remote GDB Shell Script=
|
||||
Start With=ApplicationOutput
|
||||
Use External Terminal=false
|
||||
Working Directory=
|
||||
isExecutable=false
|
||||
|
||||
[Project]
|
||||
VersionControlSupport=kdevgit
|
||||
|
||||
|
|
54
main.c
54
main.c
|
@ -10,10 +10,11 @@
|
|||
// // PART OF 1-15
|
||||
// float convert2cels(int fahr);
|
||||
|
||||
// // PART OF 1-16, 1-17, 1-18, 1-19, 1-20
|
||||
// // PART OF 1-16, 1-17, 1-18, 1-19, 1-20,1-21
|
||||
#define MAXLINE 1000
|
||||
// int getlines(char line[], int maxline);
|
||||
int detab(char s[],int lim, int col);
|
||||
// int detab(char s[],int lim, int col);
|
||||
int entab(char s[], int lim, int col);
|
||||
// void reverse(char s[MAXLINE], char d[strlen(s)]);
|
||||
// void copy(char to[], char from[]);
|
||||
|
||||
|
@ -213,7 +214,12 @@ int main() {
|
|||
// printf("%s", line);
|
||||
// }
|
||||
|
||||
|
||||
// 1-21
|
||||
int len;
|
||||
char line[MAXLINE];
|
||||
while ((len = entab(line,MAXLINE,8)) > 0) {
|
||||
printf("%s", line);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -245,7 +251,7 @@ int main() {
|
|||
// if (c == '\t') {
|
||||
// int sp=col-i%col; /*Amount of spaces to replace the tab with*/
|
||||
// int st=i; /*Starting point*/
|
||||
// for (int co = 0; co<=sp; co++ && i++) {
|
||||
// for (int co = 0; co<=sp && i < lim-1; co++ && i++) {
|
||||
// /*For each space we need to add, we increase the column count and add it
|
||||
// *to the array at position (starting point + spaces added so far)
|
||||
// * and we increase the spaces added so far*/
|
||||
|
@ -259,13 +265,49 @@ int main() {
|
|||
// /*If it is the end of the string, represented by a new line,
|
||||
// * add that new line and increase it for the \0 addition*/ {
|
||||
// s[i] = c;
|
||||
// ++i;
|
||||
// }
|
||||
// /*Add the string end and return it to the previous context*/
|
||||
// s[i] = '\0';
|
||||
// s[i+1] = '\0';
|
||||
// return i;
|
||||
// }
|
||||
|
||||
// PART OF 1-21
|
||||
int entab(char s[], int lim, int col) {
|
||||
int c, i, t;
|
||||
for (i=0,t=0; i < lim-1 && (c=getchar())!=EOF && c!='\n';i++,t++) {
|
||||
/*
|
||||
* c is the character representation as integer
|
||||
* i is the current column on the copied string
|
||||
* t is the current column on the original string
|
||||
*
|
||||
* t is used to count tab stops because i goes back when spaces are replaced by tabs.
|
||||
* i and t are both modified, however only i changes in contexts other than the routinal increase.
|
||||
* c is set to i's position and t is only used in tab stop counting
|
||||
*/
|
||||
if (t >= col && t%col == 0 && s[i-1] == ' ' && s[i-2] == ' ') {
|
||||
int x;
|
||||
for (x = i; s[x-1] == ' ' && i-col < x; x--);
|
||||
s[x] = '\t';
|
||||
i = ++x;
|
||||
}
|
||||
s[i] = c;
|
||||
}
|
||||
if (c == '\n')
|
||||
/*
|
||||
* If it is the end of the string, represented by a new line,
|
||||
* add that new line and increase it for the \0 addition
|
||||
*/ {
|
||||
s[i] = c;
|
||||
}
|
||||
/*Add the string end and return it to the previous context*/
|
||||
if (lim-1 > i) {
|
||||
s[i+1] = '\0';
|
||||
} else {
|
||||
s[lim-1] = '\0';
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
// /* copy: copy 'from' into 'to'; assume to is big enough */
|
||||
// void copy(char to[], char from[]) {
|
||||
// int i;
|
||||
|
|
Loading…
Reference in New Issue