First Upload
This commit is contained in:
BIN
10/IdanStringPointersLib
Normal file
BIN
10/IdanStringPointersLib
Normal file
Binary file not shown.
449
10/IdanStringPointersLib.h
Normal file
449
10/IdanStringPointersLib.h
Normal file
@@ -0,0 +1,449 @@
|
||||
#include "PointersLibs.h"
|
||||
|
||||
#define DAYS_IN_MONTH 30
|
||||
#define MONTHS_IN_YEAR 12
|
||||
#define ONE_HUNDRED 100
|
||||
#define ONE_THOSEND 10000
|
||||
#define BOOLEAN unsigned short
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define TEN 10
|
||||
#define TWELVE 12
|
||||
#define THIRTY 30
|
||||
#define ZERO 0
|
||||
#define ONE 1
|
||||
#define TWO 2
|
||||
#define THREE 3
|
||||
#define FOUR 4
|
||||
#define ABS(x) (x) * (((2 * (x)) + 1) % 2)
|
||||
#define MAX(x, y) (x > y) ? x : y
|
||||
#define MIN(x, y) (x < y) ? x : y
|
||||
#define BACKSLASH_ZERO '\0'
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// CharInString
|
||||
// ------------
|
||||
//
|
||||
// General :CHecks if the char exist in string.
|
||||
//
|
||||
// Parameters :
|
||||
// text - string (char[])
|
||||
// c - char (char)
|
||||
//
|
||||
// Return value : If the char exist in string (BOOLEAN).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
BOOLEAN CharInString(char text[], char c)
|
||||
{
|
||||
BOOLEAN exist = FALSE;
|
||||
unsigned short counter = ZERO;
|
||||
while ((text[counter] != c) * text[counter++]);
|
||||
exist = (text[--counter] == c);
|
||||
|
||||
return (exist);
|
||||
}
|
||||
|
||||
char * LastCharOfString(char * start_string)
|
||||
{
|
||||
while (*(start_string++));
|
||||
|
||||
return (--start_string);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// StringLenght
|
||||
// ------------
|
||||
//
|
||||
// General : Checks the lenght of string.
|
||||
//
|
||||
// Parameters :
|
||||
// text - string (char[])
|
||||
//
|
||||
// Return value : Lenght of string (unsigned short).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
unsigned short StringLenght(char *start_string)
|
||||
{
|
||||
return (LastCharOfString(start_string) - start_string);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// StringCompare
|
||||
// ------------------------
|
||||
//
|
||||
// General : Compare 2 strings.
|
||||
//
|
||||
// Parameters :
|
||||
// text1 - string (char[])
|
||||
// text2 - string (char[])
|
||||
//
|
||||
// Return value : If this 2 strings are equals (BOOLEAN).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
BOOLEAN StringCompare(char *start_stringA_index, char *start_stringB_index)
|
||||
{
|
||||
while ((*start_stringA_index) && (*(start_stringA_index++) == *(start_stringB_index++)));
|
||||
|
||||
return (*--start_stringA_index == *--start_stringB_index);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// IndexCharInString
|
||||
// -----------------
|
||||
//
|
||||
// General : Find the index of char in the string.
|
||||
//
|
||||
// Parameters :
|
||||
// text - string (char[])
|
||||
// c - char (char)
|
||||
//
|
||||
// Return value : The first index of the char in the string (unsigned short).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
unsigned short IndexCharInString(char text[], char c)
|
||||
{
|
||||
unsigned short counter = ZERO;
|
||||
while (text[counter++] != c);
|
||||
|
||||
return (--counter);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// CountCharInString
|
||||
// -----------------
|
||||
//
|
||||
// General : Count how many the char is in the string.
|
||||
//
|
||||
// Parameters :
|
||||
// text - string (char[])
|
||||
// c - char (char)
|
||||
//
|
||||
// Return value : Count of char in the string (unsigned short).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
unsigned short CountCharInString(char *start_string_index, char c)
|
||||
{
|
||||
unsigned short count = ZERO;
|
||||
while (*start_string_index)
|
||||
{
|
||||
count += (*(start_string_index++) == c);
|
||||
}
|
||||
|
||||
return (count);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// CutString
|
||||
// ---------
|
||||
//
|
||||
// General : Cut the string.
|
||||
//
|
||||
// Parameters :
|
||||
// text - string (char[])
|
||||
// start - from where (unsigned short)
|
||||
//
|
||||
// Return value : If the equation is ok (BOOLEAN).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void CutString(char *start_textA_index, char *end_textA_index, char *start_textB_index)
|
||||
{
|
||||
while (start_textA_index < end_textA_index)
|
||||
{
|
||||
*(start_textB_index++) = *(start_textA_index++);
|
||||
}
|
||||
*start_textB_index = BACKSLASH_ZERO;
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// CopyString
|
||||
// ----------
|
||||
//
|
||||
// General : Copy second string into first string.
|
||||
//
|
||||
// Parameters :
|
||||
// text - first text (char[])
|
||||
// copy - second text (char[])
|
||||
// start - from where to start (unsigned short)
|
||||
//
|
||||
// Return value : None.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void CopyString(char *start_string_index, char *start_copy_index)
|
||||
{
|
||||
while (*start_copy_index)
|
||||
{
|
||||
*(start_string_index++) = *(start_copy_index++);
|
||||
}
|
||||
*(start_string_index) = BACKSLASH_ZERO;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// LinkingString
|
||||
// -------------
|
||||
//
|
||||
// General : Copy second string into end of first string.
|
||||
//
|
||||
// Parameters :
|
||||
// textA - first text (char[])
|
||||
// textB - second text (char[])
|
||||
//
|
||||
// Return value : None.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void LinkingString(char *start_stringA_index, char *start_stringB_index)
|
||||
{
|
||||
CopyString(LastCharOfString(start_stringA_index), start_stringB_index);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// ReverseString
|
||||
// -------------
|
||||
//
|
||||
// General : Chnage to oppsite the string.
|
||||
//
|
||||
// Parameters :
|
||||
// textA - first text (char[])
|
||||
//
|
||||
// Return value : None.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void ReverseString(char textA[])
|
||||
{
|
||||
unsigned short textA_lenght = StringLenght(textA) - ONE,
|
||||
counter,
|
||||
loop_lenght = (textA_lenght + ONE) / TWO;
|
||||
char temp_char;
|
||||
for (counter = ZERO; counter < loop_lenght; counter++)
|
||||
{
|
||||
temp_char = textA[counter];
|
||||
textA[counter] = textA[textA_lenght - counter];
|
||||
textA[textA_lenght - counter] = temp_char;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// StringBInStringA
|
||||
// ----------------
|
||||
//
|
||||
// General : Check if string B exists in string A.
|
||||
//
|
||||
// Parameters :
|
||||
// textA - first text (char[])
|
||||
// textB - second text (char[])
|
||||
//
|
||||
// Return value : If string B exists in string A (BOOLEAN).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
/*BOOLEAN StringBInStringA(char textA[], char textB[])
|
||||
{
|
||||
BOOLEAN exist = FALSE;
|
||||
unsigned short textA_lenght = StringLenght(textA);
|
||||
unsigned short textB_lenght = StringLenght(textB);
|
||||
char temp_textA[textA_lenght];
|
||||
unsigned short counter;
|
||||
unsigned short loop_length = textA_lenght - textB_lenght;
|
||||
for (counter = ZERO; (counter < loop_length) * !exist; counter++)
|
||||
{
|
||||
CopyString(temp_textA, textA, ZERO);
|
||||
CutString(temp_textA, counter, textB_lenght);
|
||||
exist = StringCompare(temp_textA, textB);
|
||||
}
|
||||
|
||||
return (exist);
|
||||
}*/
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// IndexStringBInStringA
|
||||
// ---------------------
|
||||
//
|
||||
// General : Find the index of string B in string A.
|
||||
//
|
||||
// Parameters :
|
||||
// textA - first text (char[])
|
||||
// textB - second text (char[])
|
||||
//
|
||||
// Return value : Index of string B in string A (unsigned short).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
char * IndexStringBInStringA(char *start_string_a, char *start_string_b)
|
||||
{
|
||||
char *ptr_string_a_temp = start_string_a;
|
||||
char temp = BACKSLASH_ZERO;
|
||||
BOOLEAN flag = FALSE;
|
||||
unsigned short textB_lenght = StringLenght(start_string_b);
|
||||
char *address = (ptr_string_a_temp + textB_lenght);
|
||||
while ((*(address - ONE)) * !flag)
|
||||
{
|
||||
SwapChars(&temp, address);
|
||||
flag = StringCompare(ptr_string_a_temp, start_string_b);
|
||||
SwapChars(&temp, address);
|
||||
address = ((++ptr_string_a_temp) + textB_lenght);
|
||||
}
|
||||
|
||||
return (--ptr_string_a_temp);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// CountStringBInStringA
|
||||
// ---------------------
|
||||
//
|
||||
// General : Counting how many times stringB in stringA.
|
||||
//
|
||||
// Parameters :
|
||||
// *start_string_a - Pointer of first string (char[])
|
||||
// *start_string_b - Pointer of second string (char[])
|
||||
//
|
||||
// Return value : Count second string in first string (unsigned int).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
unsigned int CountStringBInStringA(char *start_string_a, char *start_string_b)
|
||||
{
|
||||
char *ptr_string_a_temp = start_string_a;
|
||||
char temp = BACKSLASH_ZERO;
|
||||
unsigned short count = ZERO;
|
||||
unsigned short textB_lenght = StringLenght(start_string_b);
|
||||
char *address = (ptr_string_a_temp + textB_lenght);
|
||||
while (*(address - ONE))
|
||||
{
|
||||
SwapChars(&temp, address);
|
||||
count += StringCompare(ptr_string_a_temp, start_string_b);
|
||||
SwapChars(&temp, address);
|
||||
address = ((++ptr_string_a_temp) + textB_lenght);
|
||||
}
|
||||
|
||||
return (count);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// CountStringBInStringA
|
||||
// ---------------------
|
||||
//
|
||||
// General : Remove first string B from string A.
|
||||
//
|
||||
// Parameters :
|
||||
// textA - first text (char[])
|
||||
// textB - second text (char[])
|
||||
//
|
||||
// Return value : None.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void RemoveStringBFromStringA(char *start_string_a, char *start_string_b)
|
||||
{
|
||||
unsigned short textB_lenght = StringLenght(start_string_b);
|
||||
char *ptr_index_stringB_in_stringA = IndexStringBInStringA(start_string_a, start_string_b);
|
||||
CopyString(ptr_index_stringB_in_stringA, ptr_index_stringB_in_stringA + textB_lenght);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// CountStringBInStringA
|
||||
// ---------------------
|
||||
//
|
||||
// General : Remove ALL string B from string A.
|
||||
//
|
||||
// Parameters :
|
||||
// textA - first text (char[])
|
||||
// textB - second text (char[])
|
||||
//
|
||||
// Return value : None.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void RemoveAllStringBFromStringA(char *start_stringA_index, char *start_stringB_index)
|
||||
{
|
||||
unsigned short loop_lenght = CountStringBInStringA(start_stringA_index, start_stringB_index);
|
||||
unsigned short counter;
|
||||
for (counter = ZERO; counter < loop_lenght; counter++)
|
||||
{
|
||||
RemoveStringBFromStringA(start_stringA_index, start_stringB_index);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// ValidParenthesesTemplate
|
||||
// ------------------------
|
||||
//
|
||||
// General : checks if the string is a good equation.
|
||||
//
|
||||
// Parameters :
|
||||
// text - string (char[])
|
||||
//
|
||||
// Return value : If the equation is ok (BOOLEAN).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 04.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
BOOLEAN ValidParenthesesTemplate(char text[])
|
||||
{
|
||||
unsigned short counter = ZERO;
|
||||
short count_parenthesis = ZERO;
|
||||
while (text[counter] * (count_parenthesis + ONE))
|
||||
{
|
||||
count_parenthesis += (text[counter] == '(');
|
||||
count_parenthesis -= (text[counter] == ')');
|
||||
}
|
||||
|
||||
return (!count_parenthesis);
|
||||
}
|
||||
|
||||
unsigned short CharToNumber(char *c)
|
||||
{
|
||||
return (unsigned short)((*c) - '0');
|
||||
}
|
||||
1169
10/PointersLibs.h
Normal file
1169
10/PointersLibs.h
Normal file
File diff suppressed because it is too large
Load Diff
66
10/ex1.c
Normal file
66
10/ex1.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <stdio.h>
|
||||
#include "IdanStringPointersLib.h"
|
||||
|
||||
#define STRING_MAX_SIZE 256
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// CountStringBInStringA
|
||||
// ---------------------
|
||||
//
|
||||
// General : Counting how many times stringB in stringA.
|
||||
//
|
||||
// Parameters :
|
||||
// *start_string_a - Pointer of first string (char[])
|
||||
// *start_string_b - Pointer of second string (char[])
|
||||
//
|
||||
// Return value : Count second string in first string (unsigned int).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//---------------------------------------------------------------------------------------
|
||||
unsigned int CountStringBInStringA(char *start_string_a, char *start_string_b)
|
||||
{
|
||||
char *ptr_string_a_temp = start_string_a;
|
||||
char temp = BACKSLASH_ZERO;
|
||||
unsigned short count = ZERO;
|
||||
unsigned short textB_lenght = StringLenght(start_string_b);
|
||||
char *address = (ptr_string_a_temp + textB_lenght);
|
||||
while (*(address - ONE))
|
||||
{
|
||||
SwapChars(&temp, address);
|
||||
count += StringCompare(ptr_string_a_temp, start_string_b);
|
||||
SwapChars(&temp, address);
|
||||
address = ((++ptr_string_a_temp) + textB_lenght);
|
||||
}
|
||||
|
||||
return (count);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// exe 1
|
||||
// -----
|
||||
// General : the program goes over the string and checks how many
|
||||
// appearences the substring makes.
|
||||
//
|
||||
// Input : a string and a word/sub-string to search for.
|
||||
//
|
||||
// Process : the program takes the sub-string and checks if the
|
||||
// string has the same sequence of chars in it.
|
||||
//
|
||||
// Output : The times it has shown up in the string.
|
||||
//-----------------------------------------------------------------
|
||||
// Proggramer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//-----------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
char stringA[STRING_MAX_SIZE] = "aaaaaaaaaaaababbbbbbbbbab";
|
||||
char stringB[STRING_MAX_SIZE] = "ab";
|
||||
printf("Count: %d\n", CountStringBInStringA(&stringA[ZERO], &stringB[ZERO]));
|
||||
|
||||
}
|
||||
58
10/ex2.c
Normal file
58
10/ex2.c
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <stdio.h>
|
||||
#include "IdanStringPointersLib.h"
|
||||
|
||||
#define STRING_MAX_SIZE 256
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// MaxCountCharInString
|
||||
// --------------------
|
||||
//
|
||||
// General : Checks which character is most often in the string.
|
||||
//
|
||||
// Parameters :
|
||||
// *start_string_index - Pointer of string (char[])
|
||||
//
|
||||
// Return value : The number of times the character appears most often (unsigned int).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//---------------------------------------------------------------------------------------
|
||||
unsigned int MaxCountCharInString(char *start_string_index)
|
||||
{
|
||||
unsigned int max = ZERO,
|
||||
count_temp;
|
||||
while (*start_string_index)
|
||||
{
|
||||
count_temp = CountCharInString(start_string_index++, *start_string_index);
|
||||
max = (count_temp > max) ? count_temp : max;
|
||||
}
|
||||
|
||||
return (max);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// exe 2
|
||||
// -----
|
||||
// General : the program checks which char repeats itself the most
|
||||
// in a string and shows how many times it shows up.
|
||||
//
|
||||
// Input : a string.
|
||||
//
|
||||
// Process : goes over every letter and checks the amount of it.
|
||||
//
|
||||
// Output : the highest repeating char and the times it appeared
|
||||
// in string.
|
||||
//
|
||||
//-----------------------------------------------------------------
|
||||
// Proggramer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//-----------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
char stringA[STRING_MAX_SIZE] = "aaaaaaaaaaaaababbbbbbbbbabbbbbbbb";
|
||||
printf("Count: %u\n", MaxCountCharInString(&stringA[ZERO]));
|
||||
|
||||
}
|
||||
145
10/ex3.c
Normal file
145
10/ex3.c
Normal file
@@ -0,0 +1,145 @@
|
||||
#include <stdio.h>
|
||||
#include "IdanStringPointersLib.h"
|
||||
|
||||
#define STRING_MAX_SIZE 256
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// SortedInDescendingOrder
|
||||
// -----------------------
|
||||
//
|
||||
// General : Checks whether the string characters are in descending order.
|
||||
//
|
||||
// Parameters :
|
||||
// *start_string_index - Pointer of string (char[])
|
||||
//
|
||||
// Return value : If the string string is descending (BOOLEAN).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//---------------------------------------------------------------------------------------
|
||||
BOOLEAN SortedInDescendingOrder(char *start_string_index)
|
||||
{
|
||||
while (*start_string_index &&
|
||||
(*(start_string_index) >= *(start_string_index++ + ONE)));
|
||||
|
||||
return !(*(start_string_index));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// SortedInAscendingOrder
|
||||
// ----------------------
|
||||
//
|
||||
// General : Checks whether the string characters are in ascending order.
|
||||
//
|
||||
// Parameters :
|
||||
// *start_string_index - Pointer of string (char[])
|
||||
//
|
||||
// Return value : If the string characters are in ascending order (BOOLEAN).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//---------------------------------------------------------------------------------------
|
||||
BOOLEAN SortedInAscendingOrder(char *start_string_index)
|
||||
{
|
||||
while (*start_string_index &&
|
||||
(*(start_string_index) <= *(start_string_index++ + ONE)));
|
||||
|
||||
return !(*(start_string_index));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// CopyEvenPlacesStringAToStringB
|
||||
// ------------------------------
|
||||
//
|
||||
// General : Transcribes the same places in the first set to another.
|
||||
//
|
||||
// Parameters :
|
||||
// *start_stringA_index - Pointer of first string (char[])
|
||||
// *start_stringB_index - Pointer of second string (char[])
|
||||
//
|
||||
// Return value : None.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//---------------------------------------------------------------------------------------
|
||||
void CopyEvenPlacesStringAToStringB(char *start_stringA_index, char *start_stringB_index)
|
||||
{
|
||||
while (*start_stringA_index)
|
||||
{
|
||||
*(start_stringB_index++) = *(start_stringA_index++);
|
||||
start_stringA_index++;
|
||||
}
|
||||
*(start_stringB_index) = BACKSLASH_ZERO;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// MaxCountCharInString
|
||||
// --------------------
|
||||
//
|
||||
// General : Checks which character is most often in the string.
|
||||
//
|
||||
// Parameters :
|
||||
// *start_string_index - Pointer of string (char[])
|
||||
//
|
||||
// Return value : The number of times the character appears most often (unsigned int).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//---------------------------------------------------------------------------------------
|
||||
unsigned short StringIsSortedAlternately(char *start_string_index)
|
||||
{
|
||||
unsigned short flag = ZERO;
|
||||
unsigned int lenght_string = StringLenght(start_string_index);
|
||||
char even_places[lenght_string];
|
||||
char odd_places[lenght_string - ONE];
|
||||
unsigned short even_array_mode = ZERO; // 0 - Not sorted, 1 - asce sorted, 2 - desc sorted, 3 - both
|
||||
unsigned short odd_array_mode = ZERO; // 0 - Not sorted, 1 - asce sorted, 2 - desc sorted, 3 - both
|
||||
CopyEvenPlacesStringAToStringB(start_string_index, &even_places[ZERO]);
|
||||
CopyEvenPlacesStringAToStringB(start_string_index + ONE, &odd_places[ZERO]);
|
||||
|
||||
even_array_mode = SortedInAscendingOrder(&even_places) * TWO + SortedInDescendingOrder(&even_places);
|
||||
odd_array_mode = SortedInAscendingOrder(&odd_places) * TWO + SortedInDescendingOrder(&odd_places);
|
||||
|
||||
flag += (even_array_mode == ONE && odd_array_mode == TWO) * TWO;
|
||||
flag += (even_array_mode == TWO && odd_array_mode == ONE);
|
||||
flag += (even_array_mode == THREE && odd_array_mode == ONE);
|
||||
flag += (even_array_mode == ONE && odd_array_mode == THREE) * TWO;
|
||||
flag += (even_array_mode == THREE && odd_array_mode == THREE) * THREE;
|
||||
flag += (even_array_mode == THREE && odd_array_mode == TWO)* TWO;
|
||||
flag += (even_array_mode == ONE && odd_array_mode == TWO)* TWO;
|
||||
|
||||
return (flag);
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
// exe 3
|
||||
// -----
|
||||
// General : the program checks if the string is ordered by the
|
||||
// given standard.
|
||||
//
|
||||
// Input : a string.
|
||||
//
|
||||
// Process : goes over every even and odd space and checks if it
|
||||
// falls under the criteria of a sorted string.
|
||||
//
|
||||
// Output : if it is a sorted string or not and what type.
|
||||
//
|
||||
//-----------------------------------------------------------------
|
||||
// Proggramer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//-----------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
|
||||
char stringA[STRING_MAX_SIZE] = "aaaaaaa\0";
|
||||
printf("Count: %u\n", StringIsSortedAlternately(&stringA[ZERO]));
|
||||
}
|
||||
71
10/ex4.c
Normal file
71
10/ex4.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
#include "IdanStringPointersLib.h"
|
||||
|
||||
#define STRING_MAX_SIZE 256
|
||||
|
||||
|
||||
int LenghtString(char *ptrStr)
|
||||
{
|
||||
char *ptrEndStr = LastCharOfString(ptrStr);
|
||||
int DifferenceStr = (ptrEndStr - ptrStr);
|
||||
return (DifferenceStr);
|
||||
}
|
||||
|
||||
void Revers(char * ptrStr)
|
||||
{
|
||||
//puts(ptrStr);
|
||||
char * ptrEnd = LastCharOfString(ptrStr);
|
||||
int length = ZERO;
|
||||
while (ptrEnd > ptrStr)
|
||||
{
|
||||
Swap(ptrStr++, ptrEnd--);
|
||||
length++;
|
||||
}
|
||||
*(ptrStr + length ) = ZERO;
|
||||
ptrStr -= length + ONE;
|
||||
|
||||
}
|
||||
|
||||
void Itoa(int num , char *ptrStr, unsigned short base)
|
||||
{
|
||||
char sign ;
|
||||
int diff;
|
||||
int length =ZERO;
|
||||
while (num > ZERO)
|
||||
{
|
||||
sign = '0';
|
||||
diff = num % base;
|
||||
sign += (diff > TEN) ? SEVEN + diff : diff;
|
||||
*(ptrStr++) = sign;
|
||||
num /= base;
|
||||
length++;
|
||||
}
|
||||
*ptrStr = ZERO;
|
||||
ptrStr -= length + ONE;
|
||||
Revers(ptrStr);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// exe 4
|
||||
// -----
|
||||
// General : the program turns a num into string.
|
||||
//
|
||||
// Input : num and base.
|
||||
//
|
||||
// Process : the program takes each number and adds the value in
|
||||
// computer code of '0' to it, to turn it to a char.
|
||||
//
|
||||
// Output : the num as a string.
|
||||
//
|
||||
//-----------------------------------------------------------------
|
||||
// Proggramer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//-----------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
char stringA[STRING_MAX_SIZE] = "aaaaaaaaaaaababbbbbbbbbab";
|
||||
char stringB[STRING_MAX_SIZE] = "ab";
|
||||
printf("Count: %d\n", CountStringBInStringA(&stringA[ZERO], &stringB[ZERO]));
|
||||
|
||||
}
|
||||
126
10/ex5.c
Normal file
126
10/ex5.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include <stdio.h>
|
||||
#include "IdanStringPointersLib.h"
|
||||
|
||||
#define BACKSLASH_ZERO '\0'
|
||||
#define BOOLEAN unsigned short
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define ZERO 0
|
||||
#define ONE 1
|
||||
#define TWO 2
|
||||
|
||||
char * LastCharOfString(char * start_string)
|
||||
{
|
||||
while (*(start_string++));
|
||||
|
||||
return (--start_string);
|
||||
}
|
||||
|
||||
unsigned short StringLenght(char *start_string)
|
||||
{
|
||||
return (LastCharOfString(start_string) - start_string);
|
||||
}
|
||||
|
||||
void SwapChars(char *ptr_char1, char *ptr_char2)
|
||||
{
|
||||
char temp_char = *ptr_char2;
|
||||
*ptr_char2 = *ptr_char1;
|
||||
*ptr_char1 = temp_char;
|
||||
}
|
||||
|
||||
BOOLEAN StringCompare(char *start_stringA_index, char *start_stringB_index)
|
||||
{
|
||||
while ((*start_stringA_index) && (*(start_stringA_index++) == *(start_stringB_index++)));
|
||||
|
||||
return (*--start_stringA_index == *--start_stringB_index);
|
||||
}
|
||||
|
||||
char * IndexStringBInStringA(char *start_string_a, char *start_string_b)
|
||||
{
|
||||
char *ptr_string_a_temp = start_string_a;
|
||||
char temp = BACKSLASH_ZERO;
|
||||
BOOLEAN flag = FALSE;
|
||||
unsigned short textB_lenght = StringLenght(start_string_b);
|
||||
char *address = (ptr_string_a_temp + textB_lenght);
|
||||
while ((*(address - ONE)) * !flag)
|
||||
{
|
||||
SwapChars(&temp, address);
|
||||
flag = StringCompare(ptr_string_a_temp, start_string_b);
|
||||
SwapChars(&temp, address);
|
||||
address = ((++ptr_string_a_temp) + textB_lenght);
|
||||
}
|
||||
|
||||
return (--ptr_string_a_temp);
|
||||
}
|
||||
|
||||
unsigned int CountStringBInStringA(char *start_string_a, char *start_string_b)
|
||||
{
|
||||
char *ptr_string_a_temp = start_string_a;
|
||||
char temp = BACKSLASH_ZERO;
|
||||
unsigned short count = ZERO;
|
||||
unsigned short textB_lenght = StringLenght(start_string_b);
|
||||
char *address = (ptr_string_a_temp + textB_lenght);
|
||||
while (*(address - ONE))
|
||||
{
|
||||
SwapChars(&temp, address);
|
||||
count += StringCompare(ptr_string_a_temp, start_string_b);
|
||||
SwapChars(&temp, address);
|
||||
address = ((++ptr_string_a_temp) + textB_lenght);
|
||||
}
|
||||
|
||||
return (count);
|
||||
}
|
||||
|
||||
void CopyString(char *start_string_index, char *start_copy_index)
|
||||
{
|
||||
while (*start_copy_index)
|
||||
{
|
||||
*(start_string_index++) = *(start_copy_index++);
|
||||
}
|
||||
*(start_string_index) = BACKSLASH_ZERO;
|
||||
}
|
||||
|
||||
void RemoveStringBFromStringA(char *start_string_a, char *start_string_b)
|
||||
{
|
||||
unsigned short textB_lenght = StringLenght(start_string_b);
|
||||
char *ptr_index_stringB_in_stringA = IndexStringBInStringA(start_string_a, start_string_b);
|
||||
CopyString(ptr_index_stringB_in_stringA, ptr_index_stringB_in_stringA + textB_lenght);
|
||||
}
|
||||
|
||||
void RemoveAllStringBFromStringA(char *start_stringA_index, char *start_stringB_index)
|
||||
{
|
||||
unsigned short loop_lenght = CountStringBInStringA(start_stringA_index, start_stringB_index);
|
||||
unsigned short counter;
|
||||
for (counter = ZERO; counter < loop_lenght; counter++)
|
||||
{
|
||||
RemoveStringBFromStringA(start_stringA_index, start_stringB_index);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// exe 5
|
||||
// -----
|
||||
// General : the program takes out all the appearnces of a word,
|
||||
// from another string.
|
||||
//
|
||||
// Input : two strings.
|
||||
//
|
||||
// Process : goes over each word in the second string, and deletes
|
||||
// the words that appear from the first one.
|
||||
//
|
||||
// Output : the original string, the second string, new string, and
|
||||
// amount of changes made.
|
||||
//
|
||||
//-----------------------------------------------------------------
|
||||
// Proggramer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 12.11.19
|
||||
//-----------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
char stringA[100] = "abgjskababababablgjkljab";
|
||||
char stringB[100] = "ab";
|
||||
RemoveAllStringBFromStringA(&stringA[0], &stringB[0]);
|
||||
printf("Lenght: %s\n", stringA);
|
||||
|
||||
}
|
||||
11
10/test.c
Normal file
11
10/test.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include "IdanStringPointersLib.h"
|
||||
|
||||
void main(void)
|
||||
{
|
||||
char stringA[100] = "abgjskababababablgjkljab";
|
||||
char stringB[100] = "ab";
|
||||
RemoveAllStringBFromStringA(&stringA[0], &stringB[0]);
|
||||
printf("Lenght: %s\n", stringA);
|
||||
|
||||
}
|
||||
BIN
10/תיעוד/Homework - 12/Debug/Homework - 12.exe
Normal file
BIN
10/תיעוד/Homework - 12/Debug/Homework - 12.exe
Normal file
Binary file not shown.
BIN
10/תיעוד/Homework - 12/Debug/Homework - 12.ilk
Normal file
BIN
10/תיעוד/Homework - 12/Debug/Homework - 12.ilk
Normal file
Binary file not shown.
BIN
10/תיעוד/Homework - 12/Debug/Homework - 12.pdb
Normal file
BIN
10/תיעוד/Homework - 12/Debug/Homework - 12.pdb
Normal file
Binary file not shown.
31
10/תיעוד/Homework - 12/Homework - 12.sln
Normal file
31
10/תיעוד/Homework - 12/Homework - 12.sln
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.572
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Homework - 12", "Homework - 12\Homework - 12.vcxproj", "{ED24374E-80FE-4D58-84D3-CAA154075EB6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{ED24374E-80FE-4D58-84D3-CAA154075EB6}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{ED24374E-80FE-4D58-84D3-CAA154075EB6}.Debug|x64.Build.0 = Debug|x64
|
||||
{ED24374E-80FE-4D58-84D3-CAA154075EB6}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{ED24374E-80FE-4D58-84D3-CAA154075EB6}.Debug|x86.Build.0 = Debug|Win32
|
||||
{ED24374E-80FE-4D58-84D3-CAA154075EB6}.Release|x64.ActiveCfg = Release|x64
|
||||
{ED24374E-80FE-4D58-84D3-CAA154075EB6}.Release|x64.Build.0 = Release|x64
|
||||
{ED24374E-80FE-4D58-84D3-CAA154075EB6}.Release|x86.ActiveCfg = Release|Win32
|
||||
{ED24374E-80FE-4D58-84D3-CAA154075EB6}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {5F88B4C9-0452-4A20-AC8A-93BC16D123B9}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,5 @@
|
||||
hw.c
|
||||
c:\users\tal levin\desktop\college\c things\homework - 12\homework - 12\hw.c(220): warning C4047: 'initializing': 'char *' differs in levels of indirection from 'char (*)[100]'
|
||||
c:\users\tal levin\desktop\college\c things\homework - 12\homework - 12\hw.c(382): warning C4013: '_getch' undefined; assuming extern returning int
|
||||
c:\users\tal levin\desktop\college\c things\homework11pointer\homework11pointer\pointer.c(201): warning C4716: 'IsPerfect': must return a value
|
||||
Homework - 12.vcxproj -> C:\Users\Tal Levin\Desktop\College\C things\Homework - 12\Debug\Homework - 12.exe
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.17763.0
|
||||
Debug|Win32|C:\Users\Tal Levin\Desktop\College\C things\Homework - 12\|
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
10/תיעוד/Homework - 12/Homework - 12/Debug/Pointer.obj
Normal file
BIN
10/תיעוד/Homework - 12/Homework - 12/Debug/Pointer.obj
Normal file
Binary file not shown.
BIN
10/תיעוד/Homework - 12/Homework - 12/Debug/hw.obj
Normal file
BIN
10/תיעוד/Homework - 12/Homework - 12/Debug/hw.obj
Normal file
Binary file not shown.
BIN
10/תיעוד/Homework - 12/Homework - 12/Debug/hw.obj.enc
Normal file
BIN
10/תיעוד/Homework - 12/Homework - 12/Debug/hw.obj.enc
Normal file
Binary file not shown.
BIN
10/תיעוד/Homework - 12/Homework - 12/Debug/vc141.idb
Normal file
BIN
10/תיעוד/Homework - 12/Homework - 12/Debug/vc141.idb
Normal file
Binary file not shown.
BIN
10/תיעוד/Homework - 12/Homework - 12/Debug/vc141.pdb
Normal file
BIN
10/תיעוד/Homework - 12/Homework - 12/Debug/vc141.pdb
Normal file
Binary file not shown.
123
10/תיעוד/Homework - 12/Homework - 12/Homework - 12.vcxproj
Normal file
123
10/תיעוד/Homework - 12/Homework - 12/Homework - 12.vcxproj
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{ED24374E-80FE-4D58-84D3-CAA154075EB6}</ProjectGuid>
|
||||
<RootNamespace>Homework12</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="hw.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="hw.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
383
10/תיעוד/Homework - 12/Homework - 12/hw.c
Normal file
383
10/תיעוד/Homework - 12/Homework - 12/hw.c
Normal file
@@ -0,0 +1,383 @@
|
||||
#pragma once
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <stdio.h>
|
||||
#include "C:\Users\Tal Levin\Desktop\College\C things\Homework11Pointer\Homework11Pointer\Pointer.c"
|
||||
#define Numbers 10
|
||||
#define Hundred 100
|
||||
#define Zero 0
|
||||
#define Ten 10
|
||||
#define One 1
|
||||
typedef char string[Hundred];
|
||||
void Nullify(char *string)
|
||||
{
|
||||
//sets the string to blanks
|
||||
short count = Zero;
|
||||
while (count < Hundred-One)
|
||||
{
|
||||
*(string + count) = ' ';
|
||||
count++;
|
||||
}
|
||||
*(string + count + One) = '\0';
|
||||
}
|
||||
char *itoa(int *num)
|
||||
{
|
||||
//turns int to char/string
|
||||
char *newString;
|
||||
char a[Hundred] = { Zero };
|
||||
newString = &a[Zero];
|
||||
int k = NumReversal(num);
|
||||
while(k>Zero)
|
||||
{
|
||||
*(newString++) = k % Ten + '0';
|
||||
k /= Ten;
|
||||
}
|
||||
*(++newString) = '\0';
|
||||
return &a[Zero];
|
||||
}
|
||||
int Length(char arr[])
|
||||
{
|
||||
//checks the length of a string
|
||||
int count = Zero;
|
||||
while (arr[count++]!='\0');
|
||||
return count-One;
|
||||
}
|
||||
int SubString(char *string, char *substring,
|
||||
char *new_string)
|
||||
{
|
||||
//checks how many times substring shows up in
|
||||
//main string and deletes them
|
||||
short len = Length(substring);
|
||||
short replaced = Zero;
|
||||
while (*(string))
|
||||
{
|
||||
short pos = 0;
|
||||
while (*(string + pos)!='\0'
|
||||
&& *(substring + pos)!='\0'
|
||||
&& *(string+pos) == *(substring+pos)
|
||||
&& pos < len)
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
if (pos == len)
|
||||
{
|
||||
string += len;
|
||||
replaced++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*new_string = *string;
|
||||
new_string++;
|
||||
string++;
|
||||
}
|
||||
}
|
||||
return replaced;
|
||||
}
|
||||
int HowManyTimes(char *string, char *substring)
|
||||
{
|
||||
//checks how many times substring shows up in
|
||||
//main string
|
||||
short len = Length(substring);
|
||||
short showups = Zero;
|
||||
while (*(string))
|
||||
{
|
||||
short pos = 0;
|
||||
while (*(string + pos) != '\0'
|
||||
&& *(substring + pos) != '\0'
|
||||
&& *(string + pos) == *(substring + pos)
|
||||
&& pos < len)
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
if (pos == len)
|
||||
{
|
||||
string += len;
|
||||
showups++;
|
||||
}
|
||||
else
|
||||
{
|
||||
string++;
|
||||
}
|
||||
}
|
||||
return showups;
|
||||
}
|
||||
short HowManySeqChars(char *str,char *frequent)
|
||||
{
|
||||
//checks which char appears the most and
|
||||
//how many times
|
||||
short max_count_chars = Zero;
|
||||
while (*str)
|
||||
{
|
||||
int count_chars = Zero;
|
||||
while (*(str + count_chars + One)
|
||||
&& *(str + count_chars) ==
|
||||
*(str + count_chars + One))
|
||||
{
|
||||
count_chars++;
|
||||
}
|
||||
if (count_chars > max_count_chars) {
|
||||
max_count_chars = count_chars;
|
||||
*frequent = *str;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
return max_count_chars + One;
|
||||
}
|
||||
void StringCut(char * string, char *even, char*odd)
|
||||
{
|
||||
//copies the even places to the even string
|
||||
//and the odd places to the odd string
|
||||
unsigned int counter = Zero;
|
||||
while (*(string + counter) != '\0')
|
||||
{
|
||||
if (counter % Two == Zero)
|
||||
{
|
||||
*even = *(string + counter);
|
||||
even++;
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*odd = *(string + counter);
|
||||
odd++;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
*even = '\0';
|
||||
*odd = '\0';
|
||||
}
|
||||
Bool MemoyanLeserogin(char *even, char *odd)
|
||||
{
|
||||
//checks if even places are going down, and odd are going up
|
||||
int lengthEven = Length(even);
|
||||
int lengthOdd = Length(odd);
|
||||
Bool found = True;
|
||||
for (int counter = Zero; counter < lengthEven - One; counter++)
|
||||
{
|
||||
if (*(even + counter) > *(even + counter + One))
|
||||
{
|
||||
found = False;
|
||||
}
|
||||
|
||||
}
|
||||
for (int counter = Zero; counter < lengthOdd - One; counter++)
|
||||
{
|
||||
if (*(odd + counter) < *(odd + counter + One))
|
||||
{
|
||||
found = False;
|
||||
}
|
||||
|
||||
}
|
||||
return found;
|
||||
}
|
||||
Bool MemoyanLeserogin2(char *even, char*odd)
|
||||
{
|
||||
//checks if odd places are going down, and even are going up
|
||||
int lengthEven = Length(even);
|
||||
int lengthOdd = Length(odd);
|
||||
Bool found = True;
|
||||
for (int counter = Zero; counter < lengthEven - One; counter++)
|
||||
{
|
||||
if (*(even + counter) < *(even + counter + One))
|
||||
{
|
||||
found = False;
|
||||
}
|
||||
|
||||
}
|
||||
for (int counter = Zero; counter < lengthOdd - One; counter++)
|
||||
{
|
||||
if (*(odd + counter) > *(odd + counter + One))
|
||||
{
|
||||
found = False;
|
||||
}
|
||||
|
||||
}
|
||||
return found;
|
||||
}
|
||||
void isStringMemoyan(char* a, char * even, char*odd)
|
||||
{
|
||||
//This function checks if the string given
|
||||
//stands by the criteria of sorted string
|
||||
StringCut(a, even, odd);
|
||||
Bool check = MemoyanLeserogin(even, odd);
|
||||
Bool check1 = MemoyanLeserogin2(even, odd);
|
||||
if (check == One)
|
||||
{
|
||||
printf("Memuyan Le Serugin\n");
|
||||
}
|
||||
if (check1 == One)
|
||||
{
|
||||
printf("Memuyan Le Serugin Hafuh\n");
|
||||
}
|
||||
if(!check1 && !check)
|
||||
{
|
||||
printf("Lo Memuyan\n");
|
||||
}
|
||||
}
|
||||
int DeleteSameInstances(char *string, char *sub,char *new_s)
|
||||
{
|
||||
//deletes all the same words of the second string from the first
|
||||
char str[Hundred];
|
||||
char *temp = &str;
|
||||
int count = Zero;
|
||||
*temp = '\0';
|
||||
while (*(sub-One) != '\0')
|
||||
{
|
||||
Cut(sub, temp);
|
||||
count += SubString(string,temp,new_s);
|
||||
Copy(string,new_s);
|
||||
sub += Length(temp)+One;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
/*
|
||||
//-----------------------------------------------------------------
|
||||
// exe 1
|
||||
// -----
|
||||
// General : the program goes over the string and checks how many
|
||||
// appearences the substring makes
|
||||
// Input : a string and a word/sub-string to search for
|
||||
// Process : the program takes the sub-string and checks if the
|
||||
// string has the same sequence of chars in it.
|
||||
// Output : The times it has shown up in the string
|
||||
//-----------------------------------------------------------------
|
||||
// Proggramer : Tal Levin
|
||||
// Student No : 212204176
|
||||
// Date : 12.11.19
|
||||
//-----------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
string str1;
|
||||
string str2;
|
||||
char *origin = &str1[Zero];
|
||||
char *sub = &str2[Zero];
|
||||
Nullify(origin);
|
||||
Nullify(sub);
|
||||
printf("Enter source string: ");
|
||||
scanf("%[^\n]%*c", str1);
|
||||
printf("Enter replace string: ");
|
||||
scanf("%[^\n]%*c", str2);
|
||||
short count = HowManyTimes(origin, sub);
|
||||
printf("Number of times: %hd\n", count);
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
// exe 2
|
||||
// -----
|
||||
// General : the program checks which char repeats itself the most
|
||||
// in a string and shows how many times it shows up
|
||||
// Input : a string
|
||||
// Process : goes over every letter and checks the amount of it
|
||||
// Output : the highest repeating char and the times it appeared
|
||||
// in string.
|
||||
//-----------------------------------------------------------------
|
||||
// Proggramer : Tal Levin
|
||||
// Student No : 212204176
|
||||
// Date : 12.11.19
|
||||
//-----------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
string arr;
|
||||
char f;
|
||||
short count = Zero;
|
||||
char *frequent = &f;
|
||||
char *str = &arr[Zero];
|
||||
printf("Enter string: ");
|
||||
scanf("%[^\n]%*c", str);
|
||||
count = HowManySeqChars(str, frequent);
|
||||
printf("the most frequent letter: %c \n", *frequent);
|
||||
printf("anount of times in: %hd", count);
|
||||
_getch();
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
// exe 3
|
||||
// -----
|
||||
// General : the program checks if the string is ordered by the
|
||||
// given standard
|
||||
// Input : a string
|
||||
// Process : goes over every even and odd space and checks if it
|
||||
// falls under the criteria of a sorted string
|
||||
// Output : if it is a sorted string or not and what type
|
||||
//-----------------------------------------------------------------
|
||||
// Proggramer : Tal Levin
|
||||
// Student No : 212204176
|
||||
// Date : 12.11.19
|
||||
//-----------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
string arr;
|
||||
char *str = &arr[Zero];
|
||||
string arr1;
|
||||
char *str1 = &arr1[Zero];
|
||||
string arr2;
|
||||
char *str2 = &arr2[Zero];
|
||||
printf("Enter string: ");
|
||||
scanf("%[^\n]%*c", str);
|
||||
isStringMemoyan(str, str1, str2);
|
||||
_getch();
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
// exe 4
|
||||
// -----
|
||||
// General : the program turns a num into string
|
||||
// Input : a num
|
||||
// Process : the program takes each number and adds the value in
|
||||
// computer code of '0' to it, to turn it to a char
|
||||
// Output : the num as a string
|
||||
//-----------------------------------------------------------------
|
||||
// Proggramer : Tal Levin
|
||||
// Student No : 212204176
|
||||
// Date : 12.11.19
|
||||
//-----------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
char *converted;
|
||||
char b[Hundred];
|
||||
converted = &b[Zero];
|
||||
Nullify(converted);
|
||||
int *num;
|
||||
int toconvert = 2103;
|
||||
num = &toconvert;
|
||||
converted = itoa(num);
|
||||
_getch();
|
||||
}
|
||||
*/
|
||||
//-----------------------------------------------------------------
|
||||
// exe 5
|
||||
// -----
|
||||
// General : the program takes out all the appearnces of a word,
|
||||
// from another string
|
||||
// Input : two strings
|
||||
// Process : goes over each word in the second string, and deletes
|
||||
// the words that appear from the first one
|
||||
// Output : the original string, the second string, new string, and
|
||||
// amount of changes made.
|
||||
//-----------------------------------------------------------------
|
||||
// Proggramer : Tal Levin
|
||||
// Student No : 212204176
|
||||
// Date : 12.11.19
|
||||
//-----------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
string str1;
|
||||
string str2;
|
||||
string str3;
|
||||
string str4;
|
||||
char *s = &str1[Zero];
|
||||
char *sub = &str2[Zero];
|
||||
char *new_s = &str3[Zero];
|
||||
char *origin = &str4[Zero];
|
||||
Nullify(s);
|
||||
Nullify(sub);
|
||||
Nullify(new_s);
|
||||
printf("Enter source string: ");
|
||||
scanf("%[^\n]%*c", s);
|
||||
printf("Enter replace string: ");
|
||||
scanf("%[^\n]%*c", sub);
|
||||
Copy(origin, s);
|
||||
int changes = DeleteSameInstances(s, sub, new_s);
|
||||
printf("Origin String: %s\n",origin);
|
||||
printf("Sub string: %s\n", sub);
|
||||
printf("New string: %s\n",new_s);
|
||||
printf("Number of changes: %hd\n", changes);
|
||||
_getch();
|
||||
}
|
||||
BIN
10/תיעוד/Homework_-_12.rar
Normal file
BIN
10/תיעוד/Homework_-_12.rar
Normal file
Binary file not shown.
Reference in New Issue
Block a user