From 10efb585132d59c524999cce8a7d688ca8d7ddcd Mon Sep 17 00:00:00 2001 From: Yousef Issa Date: Sat, 10 Aug 2024 15:26:59 +0300 Subject: [PATCH 1/4] Added implementation to surroundwithCharacter function Added implementation to surroundwithCharacter function --- .vscode/c_cpp_properties.json | 18 +++++++++++ .vscode/launch.json | 24 ++++++++++++++ .vscode/settings.json | 59 +++++++++++++++++++++++++++++++++++ .vscode/tasks.json | 29 +++++++++++++++++ main.c | 11 ++++++- 5 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..9a75488 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "C:/msys64/mingw64/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..fb02c13 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "c:/Users/Yousef/Documents/GitHub/assignment_3_repo", + "program": "c:/Users/Yousef/Documents/GitHub/assignment_3_repo/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c9e66f1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..a7a3c69 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc.exe build active file", + "command": "C:/msys64/mingw64/bin/gcc.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe", + "" + ], + "options": { + "cwd": "C:/msys64/mingw64/bin" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/main.c b/main.c index a390338..155f2f4 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,6 @@ #include using namespace std; +using namespace std; // Example: @@ -7,7 +8,15 @@ using namespace std; // c = "e" // result -> envelope string surroundWithCharacter(string str, char c) { - // TODO + int n=0; + for(i=0;str[i]!='\0';i++){ // alt syntax str.length + n++; + } + for(int i=n;i>=0;i--){ + str[i+1]=str[i]; + } + str[0]=c; + str[n+1]=c; return str; } From 45ee3e26d013e930f1910db206fcb353e408951d Mon Sep 17 00:00:00 2001 From: Yousef Issa Date: Sat, 10 Aug 2024 15:32:19 +0300 Subject: [PATCH 2/4] Update main.c --- main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.c b/main.c index 155f2f4..703baeb 100644 --- a/main.c +++ b/main.c @@ -1,12 +1,14 @@ #include using namespace std; using namespace std; +using namespace std; // Example: // str = "nvelop" // c = "e" // result -> envelope +//todo string surroundWithCharacter(string str, char c) { int n=0; for(i=0;str[i]!='\0';i++){ // alt syntax str.length From 0f609a71d13ef0d0a0f7273d0069d730946d7079 Mon Sep 17 00:00:00 2001 From: Yousef Issa Date: Sat, 10 Aug 2024 15:32:46 +0300 Subject: [PATCH 3/4] Update main.c --- main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.c b/main.c index 703baeb..0f39223 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,4 @@ #include -using namespace std; -using namespace std; using namespace std; From 5b18e4583186aa4989a373d04b92e40a4c519ea8 Mon Sep 17 00:00:00 2001 From: Yousef Issa Date: Sat, 10 Aug 2024 15:45:13 +0300 Subject: [PATCH 4/4] fixed --- main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 0f39223..dc05cf3 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,5 @@ #include +#include using namespace std; @@ -9,9 +10,9 @@ using namespace std; //todo string surroundWithCharacter(string str, char c) { int n=0; - for(i=0;str[i]!='\0';i++){ // alt syntax str.length - n++; - } + n=str.length; + str.resize(n+2) + for(int i=n;i>=0;i--){ str[i+1]=str[i]; }