First Upload

This commit is contained in:
2022-02-25 15:33:16 +02:00
commit 0c74d10f0d
295 changed files with 74784 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
[0909/152255.414:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0909/152314.222:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0909/152314.239:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0909/152314.267:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0909/152314.326:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0909/152314.336:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0909/152314.360:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0909/153314.223:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0909/153314.223:ERROR:crash_report_database_win.cc(469)] failed to stat report
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+50
View File
@@ -0,0 +1,50 @@
#include <stdio.h>
#define DIGITS 3
#define TEN 10
#define ZERO 0
//---------------------------------------------------------------------------------------
// Exercise 1
// ----------
//
// General : The program recognize if all digits are same.
//
// Input : Number with 3 digits.
//
// Process : The program summarizes all the digits and divie by last digit.
//
// Output : '0' if is it True, else is false.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 09.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
short num,
temp,
sum = ZERO;
printf("Enter number with 3 digits: ");
scanf("%hd", &num);
// Take the first digit from right and add to sum
temp = num / TEN;
sum += num - (temp * TEN);
num = temp;
temp = num / TEN;
sum += num - (temp * TEN);
num = temp;
sum += num;
// Divie the sum by last digit from right and check if (Rest == 0) and
// (result == (count of digits))
temp = sum / num;
sum %= num;
sum = sum + DIGITS - temp;
printf("If you got '0' then it is True, else is False: %hd\n", sum);
}
BIN
View File
Binary file not shown.
+49
View File
@@ -0,0 +1,49 @@
#include <stdio.h>
#define TEN 10
#define ZERO 0
//---------------------------------------------------------------------------------------
// Exercise 2
// ----------
//
// General : The program change order digits - reverse order.
//
// Input : Number with 3 digits.
//
// Process : The program take the digits from right to left and multiplier the digit
// by 10.
//
// Output : Same number like input just reverse order.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 09.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
short num,
temp,
result = ZERO;
printf("Enter number with 3 digits: ");
scanf("%hd", &num);
// Take the first digit from right to left and add to result
temp = num / TEN;
result += num - (temp * TEN);
num = temp;
temp = num / TEN;
// Multiplie the result by 10
result *= TEN;
result += num - (temp * TEN);
num = temp;
temp = num / TEN;
result *= TEN;
result += num - (temp * TEN);
printf("%hd\n", result);
}
BIN
View File
Binary file not shown.
+54
View File
@@ -0,0 +1,54 @@
#include <stdio.h>
#define TEN 10
#define ZERO 0
//---------------------------------------------------------------------------------------
// Exercise 2_2
// ------------
//
// General : The program change order digits - reverse order.
//
// Input : Number with 4 digits.
//
// Process : The program take the digits from right to left and multiplier the digit
// by 10.
//
// Output : Same number like input just reverse order.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 09.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
short num,
temp,
result = ZERO;
printf("Enter number with 4 digits: ");
scanf("%hd", &num);
// Take the first digit from right to left and add to result
temp = num / TEN;
result += num - (temp * TEN);
num = temp;
temp = num / TEN;
// Multiplie the result by 10
result *= TEN;
result += num - (temp * TEN);
num = temp;
temp = num / TEN;
result *= TEN;
result += num - (temp * TEN);
num = temp;
temp = num / TEN;
result *= TEN;
result += num - (temp * TEN);
printf("%hd\n", result);
}
BIN
View File
Binary file not shown.
+59
View File
@@ -0,0 +1,59 @@
#include <stdio.h>
#define SIXTY 60
//---------------------------------------------------------------------------------------
// Exercise 3
// ----------
//
// General : The program calculates difference between 2 times.
//
// Input : 2 times by HH:MM:SS format.
//
// Process : The program coverts the hours and minutes to seconds and calculate
// the seconds by subtraction.
//
// Output : Time by format HH:MM:SS.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 09.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
short hours1,
minutes1,
hours2,
minutes2;
int seconds1,
seconds2;
printf("Enter the first time (HH:MM:SS): ");
scanf("%hd:%hd:%d", &hours1, &minutes1, &seconds1);
printf("Enter the second time (HH:MM:SS): ");
scanf("%hd:%hd:%d", &hours2, &minutes2, &seconds2);
// Change the hours to minutes
minutes1 += hours1 * SIXTY;
minutes2 += hours2 * SIXTY;
// Change the minutes to seconds
seconds1 += minutes1 * SIXTY;
seconds2 += minutes2 * SIXTY;
// Subtraction between times as seconds
seconds1 -= seconds2;
// Change the seconds to minutes
minutes1 = seconds1 / SIXTY;
// Rest for seconds
seconds1 %= SIXTY;
// Change the minutes to hours
hours1 = minutes1 / SIXTY;
// Rest for minutes
minutes1 %= SIXTY;
printf("%02hd:%02hd:%02d\n", hours1, minutes1, seconds1);
}
BIN
View File
Binary file not shown.
+26
View File
@@ -0,0 +1,26 @@
#define APPLE_COUNT 10
#define APPLE_COST 5
#define TWO 2
//---------------------------------------------------------------------------------------
// Exercise 4
// ----------
//
// General : The program calculates what is the cost for bananas and apples.
//
// Input : None.
//
// Process : The program calculate price by multiply and amount.
//
// Output : None.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 09.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
unsigned char bananas = APPLE_COUNT + TWO;
unsigned short sum_cost = (APPLE_COUNT * APPLE_COST) +
(bananas * APPLE_COST * TWO);
}
BIN
View File
Binary file not shown.
+30
View File
@@ -0,0 +1,30 @@
#include <stdio.h>
#define TWO 2
//---------------------------------------------------------------------------------------
// Exercise 5
// ----------
//
// General : The program calculates right angled triangular area.
//
// Input : 2 ribs of the right angled triangle.
//
// Process : The program calculate rib * rib / 2.
//
// Output : The right angled triangular area.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 09.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
unsigned short rib1,
rib2,
area;
printf("Enter 2 ribs of right angled triangle: ");
scanf("%hd%hd", &rib1, &rib2);
area = rib1 * rib2 / TWO;
printf("The area is: %hd\n", area);
}
BIN
View File
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
#include <stdio.h>
void main(void)
{
short num = 2;
num = !-2;
printf("%hd", num);
}
Binary file not shown.
+449
View 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
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
+66
View 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]));
}
BIN
View File
Binary file not shown.
+58
View 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]));
}
BIN
View File
Binary file not shown.
+145
View 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
View 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
View 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);
}
BIN
View File
Binary file not shown.
+11
View 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);
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
@@ -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\|
@@ -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>
@@ -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();
}
Binary file not shown.
+479
View File
@@ -0,0 +1,479 @@
#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'
#define MAX_SIZE_STRING 256
//---------------------------------------------------------------------------------------
// 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 *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 (flag);
}
//---------------------------------------------------------------------------------------
// 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');
}
//---------------------------------------------------------------------------------------
// 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);
}
+1167
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
+95
View File
@@ -0,0 +1,95 @@
#include "IdanStringPointersLib.h"
#include <stdio.h>
//---------------------------------------------------------------------------------------
// Highest CountTheLongestIdenticalCharacterSequence
// -------------------------------------------------
//
// General : The function checks the highest sequence of chars in a string
//
// Parameters :
// *ptr_start - Pointer to a place in a vector(char)
//
// Return Value : Highest sequence
//
//---------------------------------------------------------------------------------------
unsigned short CountTheLongestIdenticalCharacterSequence(char * ptr_start)
{
unsigned short max_sum = ONE,
temp_sum = ONE;
ptr_start++;
while (*(ptr_start++))
{
if (*ptr_start != *(ptr_start - ONE))
{
max_sum = (max_sum < temp_sum) ? temp_sum : max_sum;
temp_sum = ZERO;
}
temp_sum++;
}
return (max_sum);
}
unsigned short IndexOfStringWithLongestIdenticalCharacterSequence(char *ptr_mat_start)
{
unsigned short max_sum = ZERO,
temp_sum = ZERO,
counter = ZERO,
index = ZERO;
unsigned int string_amount = (unsigned int)(ptr_mat_start) + (MAX_SIZE_STRING * TEN);
for (counter = ZERO; (unsigned int)(ptr_mat_start) < string_amount; counter++)
{
temp_sum = CountTheLongestIdenticalCharacterSequence(ptr_mat_start);
if (temp_sum > max_sum)
{
max_sum = temp_sum;
index = counter;
}
ptr_mat_start += MAX_SIZE_STRING;
}
return (index);
}
//---------------------------------------------------------------------------------------
// EX #1
// -----
//
// General : The program gets 10 strings and checks what string is with the highest
// sequence of chars
//
// Input : 10 strings
//
// Process : The program runs on a string and checks what is the highest sequence than
// it compares it to the max
//
// Output : the highest sequence in a the 10 strings
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : 211675038
// Date: 19.11.2019
//---------------------------------------------------------------------------------------
void main(void)
{
typedef char string[MAX_SIZE_STRING];
string s1 = "aaaabbbbbccccccccccccccc\0";
string s2 = "aaaabbbbbccccvcccccccccc\0";
string s3 = "aaaabbbbbccccycccccccccc\0";
string s4 = "aaaabbbbbcccgccccccccccc\0";
string s5 = "aaaabbbbbccccckccccccccc\0";
string s6 = "aaaabbbbbccccchccccccccc\0";
string s7 = "aaaabbbbbccccncccccccccc\0";
string s8 = "aaaabbbbbccccjcccccccccc\0";
string s9 = "aaaabbbbbcccmccccccccccc\0";
string s10 = "aaaabbbbbccccucccccccccc\0";
string arr[10] = {*s5, *s2, *s3, *s4, *s1, *s6, *s7, *s8, *s9, *s10};
unsigned short max = PointerOfStringWithLongestIdenticalCharacterSequence(&arr[0]);
printf("%hu\n", max);
}
BIN
View File
Binary file not shown.
+84
View File
@@ -0,0 +1,84 @@
#include "IdanStringPointersLib.h"
#include <stdio.h>
#define ROW 5
#define COL 5
unsigned short SumValuesInPointers(BOOLEAN * ptr_start, BOOLEAN * ptr_end)
{
unsigned short sum;
for (sum = ZERO; ptr_start <= ptr_end; sum += *(ptr_start++));
return (sum);
}
unsigned short CountNeighbors(BOOLEAN *ptr_mat, BOOLEAN *ptr_player)
{
unsigned short neighbords_count = ZERO;
unsigned short player_row = (ptr_player - ptr_mat) / ROW;
unsigned short player_col = (ptr_player - ptr_mat) % COL;
// Add the sum of the vector above the cell
neighbords_count += (player_row > ZERO) * SumValuesInPointers(ptr_mat + (MAX(player_row - ONE, ZERO)) * ROW + (MAX(player_col - ONE, ZERO)),
ptr_mat + (MAX(player_row - ONE, ZERO)) * ROW + (MIN(player_col + ONE, COL - ONE)));
// Add the sum of the vector middle the cell
neighbords_count += SumValuesInPointers(ptr_mat + (player_row) * ROW + (MAX(player_col - ONE, ZERO)),
ptr_mat + (player_row) * ROW + (MIN(player_col + ONE, COL - ONE))) - *ptr_player;
// Add the sum of the vector below the cell
neighbords_count += (player_row < ROW) * SumValuesInPointers(ptr_mat + (MIN(player_row + ONE, ROW - ONE)) * ROW + (MAX(player_col - ONE, ZERO)),
ptr_mat + (MIN(player_row + ONE, ROW - ONE)) * ROW + (MIN(player_col + ONE, COL - ONE)));
return (neighbords_count);
}
void OneLive(BOOLEAN *ptr_mat)
{
BOOLEAN *ptr_mat_start = ptr_mat;
BOOLEAN *ptr_mat_end = ptr_mat_start + (ROW * COL);
for (; ptr_mat_start < ptr_mat_end; *(ptr_mat_start++) = (CountNeighbors(ptr_mat, ptr_mat_start) == TWO));
}
void GameLife(BOOLEAN *ptr_mat, unsigned short lives)
{
for (; lives; lives--)
{
OneLive(ptr_mat);
PrintMatrix(ptr_mat);
printf("\n");
}
}
void ResetMatrix(BOOLEAN *ptr_mat)
{
BOOLEAN *end_mat = ptr_mat + (ROW * COL);
for (; ptr_mat < end_mat; *(ptr_mat++) %= TWO);
}
void PrintVector(BOOLEAN *ptr_vec) // Lenght = COL
{
BOOLEAN *end_vec = ptr_vec + COL;
for (; ptr_vec < end_vec; ptr_vec++)
{
printf("%hu, ", *ptr_vec);
}
}
void PrintMatrix(BOOLEAN *ptr_mat) // Lenght = ROW
{
BOOLEAN *end_mat = ptr_mat + (ROW * COL);
for (; ptr_mat < end_mat; ptr_mat += COL)
{
PrintVector(ptr_mat);
printf("\n");
}
}
void main(void)
{
BOOLEAN mat[ROW][COL] = {{1,1,1,0,1}, {1,1,1,1,1}, {1,1,1,1,1}, {1,0,1,0,1}, {1,0,1,0,1}};
PrintMatrix(mat);
printf("\n");
GameLife(mat, THREE);
}
BIN
View File
Binary file not shown.
+68
View File
@@ -0,0 +1,68 @@
#include "IdanStringPointersLib.h"
#include <stdio.h>
#define ROW 2
#define COL 2
BOOLEAN StringIsSubstringInVec(char * ptr_vec, char * ptr_string) // Lenght vector = COL
{
char *strings_amount = ptr_vec + (COL * MAX_SIZE_STRING);
for (;ptr_vec < strings_amount && !(ptr_vec != ptr_string) * StringBInStringA(ptr_vec, ptr_string); ptr_vec += MAX_SIZE_STRING);
return ((ptr_vec != ptr_string) * StringBInStringA(ptr_vec, ptr_string));
}
BOOLEAN StringIsSubstringInMat(char * ptr_mat, char * ptr_string) // Lenght = ROW
{
unsigned int step = COL * MAX_SIZE_STRING;
char *vectors_amount = ptr_mat + (ROW * step);
for (; ptr_mat < vectors_amount && !((ptr_mat != ptr_string) * StringIsSubstringInVec(ptr_mat, ptr_string)); ptr_mat += step);
return ((ptr_mat != ptr_string) * StringIsSubstringInVec(ptr_mat, ptr_string));
}
BOOLEAN HaveSubstringInVec(char * ptr_mat, char * ptr_vec) // בודק בווקטור אם אחד האיברים הוא תת מחרוזת במטריצה
{
char *strings_amount = ptr_vec + (COL * MAX_SIZE_STRING);
for (; ptr_vec < strings_amount && !(StringIsSubstringInMat(ptr_mat, ptr_vec)); ptr_vec += MAX_SIZE_STRING);
return (StringIsSubstringInMat(ptr_mat, ptr_vec));
}
BOOLEAN HaveSubstringInMat(char * ptr_mat) // בודק אם קיימת תת מחרוזת במטריצה למחרוזת במטריצה
{
unsigned int step = COL * MAX_SIZE_STRING;
char *vectors_amount = ptr_mat + (ROW * step);
char *ptr_temp_mat = ptr_mat;
for (; ptr_mat < vectors_amount && !(HaveSubstringInVec(ptr_temp_mat, ptr_mat)); ptr_mat += step);
return (HaveSubstringInVec(ptr_temp_mat, ptr_mat));
}
//---------------------------------------------------------------------------------------
// EX #3
// -----
//
// General : The program gets a matrix of string and checks if one of the string is a
// substring to another string
//
// Input : matrix of string
//
// Process : The program runs on a string and if he is a substring of one of the other
// string till it is out of string to check
//
// Output : True or False
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : 211675038
// Date: 19.11.2019
//---------------------------------------------------------------------------------------
void main(void)
{
typedef char string[MAX_SIZE_STRING];
string mat[ROW][COL] = { {"hello", "world"} , { "idan", "hel"}};
printf("%hu\n", HaveSubstringInMat(mat));
}
+1677
View File
File diff suppressed because it is too large Load Diff
+44
View File
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <malloc.h>
#include "PointersLibs.h"
int * EvenSubArray(int vec[], int len, int *ptr_even)
{
int * ptr_even_vec = (int)malloc(sizeof(int));
unsigned int counter;
for (counter = ZERO; counter < len; counter++)
{
if (!(vec[counter] % TWO))
{
(*ptr_even)++;
ptr_even_vec = realloc(ptr_even_vec, (*ptr_even));
*(ptr_even_vec++) = vec[counter];
}
}
return (ptr_even_vec);
}
//---------------------------------------------------------------------------------------
// exe 1
// -----
//
// General : The program gets an array and separates the even
// numbers from it to the pointer.
//
// Input : an array of numbers, its length.
//
// Process : the program goes over the array and puts the even nums
// in the pointer array.
//
// Output : if there are even nums, and if there are, print them.
//
//---------------------------------------------------------------------------------------
// Proggramer : Cohen Idan
// Student No : 211675038
// Date : 21.11.19
//---------------------------------------------------------------------------------------
void main(void)
{
}
BIN
View File
Binary file not shown.
+58
View File
@@ -0,0 +1,58 @@
#include <stdio.h>
#include <malloc.h>
#include "PointersLibs.h"
void SearchLongestWord(char s[], char **l)
{
*l = malloc(sizeof(char));
char *ptr_s = s,
*ptr_temp_s,
*ptr_last_char = LastCharOfString(s);
unsigned short max_lenght = ZERO;
while (ptr_s < ptr_last_char)
{
ptr_temp_s = IndexCharInPointers(ptr_s, ptr_last_char, ' ');
if (ptr_temp_s - ptr_s > max_lenght)
{
max_lenght = ptr_temp_s - ptr_s;
*l = realloc(*l, max_lenght);
CopyPointers(*l, ptr_s, ptr_temp_s);
(*LastCharOfString(*l)) = BACKSLASH_ZERO;
}
ptr_s = ptr_temp_s + ONE;
}
}
//---------------------------------------------------------------------------------------
// exe 2
// -----
//
// General : the program gets a string and searches for the longest
// word in it and saves it.
//
// Input : a string and a pointer of pointers.
//
// Process : the program goes over the array and checks if each
// word finds is longer than the last one that
// was longest.
//
// Output : the longest word.
//
//---------------------------------------------------------------------------------------
// Proggramer : Cohen Idan
// Student No : 211675038
// Date : 21.11.19
//---------------------------------------------------------------------------------------
void main(void)
{
typedef char string[MAX_SIZE_STRING];
string s = "Your feedback plays an important role in helping other buyers choose products and sellers.";
char f;
char *f1 = &f;
char *f2 = &f1;
SearchLongestWord(s, f2);
printf("%s\n", f1);
free(f1);
}
BIN
View File
Binary file not shown.
+47
View File
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <malloc.h>
#include "PointersLibs.h"
void InsertNumberToRowInMat(int *ptr_mat, unsigned short mat_col, unsigned short custom_row, int number)
{
ptr_mat = ptr_mat + (custom_row * (mat_col));
while (mat_col)
{
*(ptr_mat + mat_col--) = number % TEN;
number /= TEN;
}
}
//---------------------------------------------------------------------------------------
// exe 3
// -----
//
// General : The program takes the last digits according to input
// from each number inputted.
//
// Input : how many numbers to take and input, and how many digits
// at least for the input.
//
// Process : the program gets input from user, then takes the
// last numbers according to input, and makes a char
// matrix out of it.
//
// Output : numbers in a matrix looking form.
//
//---------------------------------------------------------------------------------------
// Proggramer : Cohen Idan
// Student No : 211675038
// Date : 21.11.19
//---------------------------------------------------------------------------------------
void main(void)
{
unsigned short HowManyNums = 4,
HowManyDigits = 3;
int *mat = malloc(sizeof(int) * HowManyNums * HowManyDigits);
InsertNumberToRowInMat(mat, HowManyDigits, 0, 167367);
InsertNumberToRowInMat(mat, HowManyDigits, 1, 6376);
InsertNumberToRowInMat(mat, HowManyDigits, 2, 2462172);
InsertNumberToRowInMat(mat, HowManyDigits, 3, 64036);
free(mat);
}
BIN
View File
Binary file not shown.
+48
View File
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <malloc.h>
#include "PointersLibs.h"
void EvenAndOddToTwoVec(int vec[], unsigned short vec_size, int *evensize, int *oddsize, int **even, int **odd)
{
*even = malloc(sizeof(int));
*odd = malloc(sizeof(int));
*evensize = ZERO;
*oddsize = ZERO;
unsigned short counter;
for (counter = ZERO; counter < vec_size; counter++)
{
if (!(vec[counter] % TWO))
{
*even = realloc(*even, ++(*evensize));
*((*even) + (*evensize) - ONE) = vec[counter];
}
else
{
*odd = realloc(*odd, ++(*oddsize));
*((*odd) + (*oddsize) - ONE) = vec[counter];
}
}
}
//---------------------------------------------------------------------------------------
// exe 4
// -----
// General : the program gets an array of numbers, and breaks it
// down to even numbers and odd numbers.
//
// Input : an array of numbers.
//
// Process : goes over the arrau and adds the even num to the even
// pointer and the odd to odd pointer.
//
// Output : The even array and odd array.
//
//---------------------------------------------------------------------------------------
// Proggramer : Cohen Idan
// Student No : 211675038
// Date : 21.11.19
//---------------------------------------------------------------------------------------
void main(void)
{
}
BIN
View File
Binary file not shown.
+48
View File
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <malloc.h>
#include "PointersLibs.h"
BOOLEAN SentenceALowerThenSentenceB(char *ptr_sentence_a, char *ptr_sentence_b)
{
while (*(ptr_sentence_a++) == *(ptr_sentence_b++) && *ptr_sentence_a && *ptr_sentence_b);
return ((*(--ptr_sentence_a) <= *(--ptr_sentence_b)));
}
void SwapPointers(char **first_pointer, char **second_pointer)
{
char *temp_pointer = *first_pointer;
*first_pointer = *second_pointer;
*second_pointer = temp_pointer;
}
void SortStringAsDictionary(char **ptr_vec, unsigned short lenght)
{
char **low_sentence = ptr_vec;
unsigned short counter_loop1, counter_loop2;
for (counter_loop1 = ZERO; counter_loop1 < lenght; counter_loop1++)
{
for (counter_loop2 = counter_loop1; counter_loop2 < lenght; counter_loop2++)
{
(SentenceALowerThenSentenceB(*ptr_vec ,*low_sentence) ? ZERO : SwapPointers(ptr_vec, low_sentence));
*low_sentence = LastCharOfString(*low_sentence);
}
*ptr_vec = LastCharOfString(*ptr_vec) + ONE;
*low_sentence = *ptr_vec;
}
}
// --------------------------------------------------------------------------------------
// Exe 5
// -----
//
//
//---------------------------------------------------------------------------------------
// Proggramer : Cohen Idan
// Student No : 211675038
// Date : 21.11.19
//---------------------------------------------------------------------------------------
void main(void)
{
}
+116
View File
@@ -0,0 +1,116 @@
#include "PointersLibs.h"
#include <stdio.h>
#include <malloc.h>
void Swap(int *num1, int *num2)
{
//swaps between two numbers
int temp = *num1;
*num1 = *num2;
*num2 = temp;
}
void SortMat(int *mat,int max_size)
{
//sorts them by ascending order
for (int count = ZERO; count < max_size; count++)
{
for (int counter = count + ONE; counter < max_size; counter++)
{
(*(mat + count) > *(mat + counter)) ?
Swap((mat + count) ,(mat + counter)): ZERO;
}
}
}
void Switcharoo(int *begin,int *stop)
{
//switches between numbers in a certain
while (stop > begin)
{
int temp = *begin;
*begin = *stop;
*stop = temp;
stop--;
begin++;
}
}
void Special_Print_for_sixth(int *mat,int size)
{
//special print for ex 6
int amnt = size*size;
for (int count = ZERO; count < size; count++)
{
for (int counter = count; counter < size*size; counter += size)
{
printf("%d ", *(mat + counter));
}
printf("\n");
}
}
void PutIn(int *mat,int num,int N)
{
*mat = num;
int maxsize = N * N;
SortMat(mat,maxsize);
for (int count = ZERO; count < maxsize; count++)
{
//switches the even rows values places
//so that when you print it shows ok
((count / N) % TWO == ONE) ? Switcharoo((mat + count), (mat + count + N - ONE)) : ZERO;
((count / N) % TWO == ONE) ? count += N - ONE : ZERO;
}
}
//---------------------------------------------------------------------------------------
// exe 6
// -----
//
// General : the program sorts the numbers in an ascending order
// and then adds a number that is desiered to the matrix, sorts it
// again.
//
// Input : size o the matrix, and N^2 of numbers.
//
// Process : sorts in ascending order and then sorts them according to the wanted way.
//
// Output : prints the new matrix.
//
//---------------------------------------------------------------------------------------
// Proggramer : Cohen Idan
// Student No : 211675038
// Date : 22.11.19
//---------------------------------------------------------------------------------------
void main(void)
{
int N = ZERO;
int *mat = (int*)malloc(sizeof(int));
printf("enter Size: ");
scanf("%d", &N);
int maxsize = N * N;
int num = ZERO;
for (int sofer = ZERO; sofer < maxsize; sofer++)
{
mat = realloc(mat, sizeof(int)*(sofer+ONE));
printf("enter no.%d: ",sofer+ONE);
scanf("%d", &(*(mat+sofer)));
}
SortMat(mat,maxsize);
for (int count = ZERO; count < maxsize; count++)
{
//switches the even rows values places
//so that when you print it shows ok
((count / N) % TWO == ONE) ? Switcharoo((mat + count), (mat + count + N - ONE)) : ZERO;
((count / N) % TWO == ONE) ? count += N - ONE : ZERO;
}
Special_Print_for_sixth(mat, N);
printf("enter number to enter: ");
scanf("%d", &num);
PutIn(mat, num, N);
Special_Print_for_sixth(mat, N);
free(mat);
}
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
+12
View File
@@ -0,0 +1,12 @@
#include "PointersLibs.h"
BOOLEAN EvenNumber(int num)
{
return (num & !MASK_FIRST_BIT);
}
void main(void)
{
int num = 2;
printf("%d\n" ,EvenNumber(3));
}
BIN
View File
Binary file not shown.
+21
View File
@@ -0,0 +1,21 @@
#include "PointersLibs.h"
int RotateLeft(unsigned int num, int count)
{
unsigned short counter;
unsigned int temp;
for (counter = ZERO; counter < count; counter++)
{
temp = (num >> ((sizeof(num) * EIGHT) - ONE));
num <<= ONE;
num |= temp;
}
return num;
}
void main(void)
{
unsigned int x = 1000000000;
printf("%u\n", RotateLeft(x,30));
}
BIN
View File
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
#include "PointersLibs.h"
BOOLEAN EvenBits(byte b)
{
BOOLEAN even = TRUE;
unsigned short loop_length;
for (loop_length = sizeof(b) * EIGHT; loop_length; loop_length--)
{
even ^= b & MASK_FIRST_BIT;
b >>= ONE;
}
return (even);
}
void main(void)
{
byte b = 3;
printf("%hu\n", EvenBits(b));
}
BIN
View File
Binary file not shown.
+159
View File
@@ -0,0 +1,159 @@
#include "PointersLibs.h"
#define ROWS 4
void RemoveBits(byte *row, unsigned short count)
{
*row >>= count;
}
unsigned short CountBits(byte b)
{
unsigned short counter = ZERO,
loop_length = sizeof(b) * EIGHT;
while (loop_length--)
{
counter += !EvenNumber(b);
b >>= ONE;
}
return (counter);
}
void PrintGetRow()
{
printf("Enter row number (1-4): ");
}
void PrintGetRemoveCount()
{
printf("Enter many bits: ");
}
void PrintPlayerWon()
{
printf("You won!\n");
}
void PrintBotWon()
{
printf("The bot won :(\n");
}
unsigned short InputRow()
{
unsigned short row;
scanf("%hu", &row);
return (row);
}
unsigned short InputRemoveCount()
{
unsigned short remove_count;
scanf("%hu", &remove_count);
return (remove_count);
}
BOOLEAN EvenBits(byte b)
{
return (!(CountBits(b) % TWO));
}
unsigned short SumBits(byte *vec, unsigned short length)
{
unsigned short sum = ZERO;
while (length--)
{
sum += CountBits(*(vec++));
}
return (sum);
}
void PrintBits(byte b)
{
unsigned short length = sizeof(b) * EIGHT;
while (length--)
{
printf("%hu,", !EvenNumber(b));
b >>= ONE;
}
}
void PrintRows(byte *rows, unsigned short length)
{
while (length--)
{
PrintBits(*(rows++));
printf("\n");
}
}
byte * MaxBitsRow(byte *rows, unsigned short length)
{
unsigned short max_count = ZERO,
temp_count;
byte *max_row;
while (length--)
{
temp_count = CountBits(*rows);
if (temp_count > max_count)
{
max_count = temp_count;
max_row = rows;
}
rows++;
}
return (max_row);
}
void Bot(byte *rows, unsigned short length)
{
byte *max_row = MaxBitsRow(rows, length);
RemoveBits(max_row, MAX(CountBits(*max_row) / TWO * TWO, ONE));
}
void main(void)
{
byte rows[ROWS] = {0x7f, 0x1f, 0x7, 0x1};
unsigned short row = -ONE, remove_count = ZERO;
BOOLEAN player = FALSE;
while (SumBits(rows, ROWS))
{
PrintRows(rows, ROWS);
printf("\n\n");
row = -ONE;
remove_count = ZERO;
player = !player;
if (player)
{
while (!(row < ROWS))
{
PrintGetRow();
row = InputRow();
}
while (!(ZERO < remove_count && remove_count <= CountBits(rows[row])))
{
PrintGetRemoveCount();
remove_count = InputRemoveCount();
}
RemoveBits(&rows[row], remove_count);
}
else
{
Bot(rows, ROWS);
}
}
if (player)
{
PrintPlayerWon();
}
else
{
PrintBotWon();
}
}
BIN
View File
Binary file not shown.
+183
View File
@@ -0,0 +1,183 @@
#include "PointersLibs.h"
#define ROWS 3
void RemoveBits(byte *row, unsigned short count)
{
*row >>= count;
}
unsigned short CountBits(byte b)
{
unsigned short counter = ZERO,
loop_lenght = sizeof(b) * EIGHT;
while (loop_lenght--)
{
counter += !EvenNumber(b);
b >>= ONE;
}
return (counter);
}
void PrintGetRow()
{
printf("Enter row number (1-3): ");
}
void PrintGetRemoveCount()
{
printf("Enter many bits: ");
}
void PrintPlayerWon()
{
printf("You won!\n");
}
void PrintBotWon()
{
printf("The bot won :(\n");
}
unsigned short InputRow()
{
unsigned short row;
scanf("%hu", &row);
return (row);
}
unsigned short InputRemoveCount()
{
return (InputRow());
}
unsigned short SumBits(byte *vec, unsigned short lenght)
{
unsigned short sum = ZERO;
while (lenght--)
{
sum += CountBits(*(vec++));
}
return (sum);
}
void PrintBits(byte b)
{
unsigned short lenght = sizeof(b) * EIGHT;
while (lenght--)
{
printf("%hu,", !EvenNumber(b));
b >>= ONE;
}
}
void PrintRows(byte *rows, unsigned short lenght)
{
while (lenght--)
{
PrintBits(*(rows++));
printf("\n");
}
}
byte * MaxBitsRow(byte *rows, unsigned short lenght)
{
unsigned short max_count = ZERO,
temp_count;
byte *max_row;
while (lenght--)
{
temp_count = CountBits(*rows);
if (temp_count > max_count)
{
max_count = temp_count;
max_row = rows;
}
rows++;
}
return (max_row);
}
byte * OddMaxBitsRow(byte *rows, unsigned short length)
{
unsigned short max_count = ZERO,
temp_count;
byte *odd_max_row = MaxBitsRow(rows, length);
while (length--)
{
if (!EvenBits(*rows))
{
temp_count = CountBits(*rows);
if (temp_count > max_count)
{
max_count = temp_count;
odd_max_row = rows;
}
}
rows++;
}
return (odd_max_row);
}
void Bot(byte *rows, unsigned short lenght)
{
byte *max_row = OddMaxBitsRow(rows, lenght);
unsigned short sum_bits = SumBits(rows, lenght);
BOOLEAN EvenArea = EvenNumber(sum_bits);
unsigned short count_bits = CountBits(*max_row);
unsigned short remove_count = EvenNumber(sum_bits - (count_bits / TWO)) ? (count_bits / TWO) : (count_bits / TWO) + ONE;
RemoveBits(max_row, remove_count); // EvenArea ? (CountBits(*max_row) / TWO * TWO - ONE) / TWO: (CountBits(*max_row) / TWO * TWO - ONE));
}
void main(void)
{
byte rows[ROWS] = {0x7f, 0x1f, 0x7};
unsigned short row = -ONE, remove_count = ZERO;
BOOLEAN player = FALSE;
while (SumBits(rows, ROWS) != ONE)
{
PrintRows(rows, ROWS);
printf("\n\n");
row = -ONE;
remove_count = ZERO;
player = !player;
if (player)
{
while (!(row < ROWS))
{
PrintGetRow();
row = InputRow();
}
while (!(ZERO < remove_count && remove_count <= CountBits(rows[row])))
{
PrintGetRemoveCount();
remove_count = InputRemoveCount();
}
RemoveBits(&rows[row], remove_count);
}
else
{
printf("Bot:\n");
Bot(rows, ROWS);
}
}
PrintRows(rows, ROWS);
printf("\n\n");
if (player)
{
PrintPlayerWon();
}
else
{
PrintBotWon();
}
}
File diff suppressed because it is too large Load Diff
+120
View File
@@ -0,0 +1,120 @@
#include "PointersLibs.h"
#define MAXSIZE 256
#define MAT_SIZE 6
struct study_hours
{
string teacher;
unsigned short subject;
int total_students;
};
unsigned int TeachesCountMaxHoursStraightInDay(struct study_hours *ptr_mat_day, unsigned short rows, unsigned short cols)
{
unsigned short max = ZERO;
unsigned short counter = ONE;
struct study_hours *ptr_temp = ptr_mat_day + cols;
rows--;
while (rows--)
{
if (!StringCompare(&((*ptr_mat_day).teacher), &((*ptr_temp).teacher)))
{
max = (counter > max) ? counter : max;
counter = ZERO;
}
counter++;
ptr_mat_day += cols;
ptr_temp += cols;
}
return (max);
}
struct study_hours * TeachesMaxHoursStraightInDay(struct study_hours *ptr_mat_day, unsigned short rows, unsigned short cols)
{
unsigned short counter = ONE,
max = ZERO;
struct study_hours *ptr_temp = ptr_mat_day + cols;
struct study_hours *ptr_max_teacher = ptr_mat_day;
rows--;
while (rows--)
{
if (!StringCompare(&((*ptr_mat_day).teacher), &((*ptr_temp).teacher)))
{
max = (counter > max) ? counter : max;
counter = ZERO;
}
counter++;
ptr_mat_day += cols;
ptr_temp += cols;
}
return (ptr_max_teacher);
}
// Ex1
struct study_hours * WhoTeachesMoreThanFourHoursStraight(struct study_hours *ptr_mat, unsigned short rows, unsigned short cols)
{
unsigned short day = cols;
while (TeachesCountMaxHoursStraightInDay(ptr_mat++, rows, cols) < FIVE && day--);
return (TeachesMaxHoursStraightInDay(--ptr_mat, rows, cols));
}
unsigned short TeacherCountOfHoursInDay(struct study_hours *ptr_mat, unsigned short rows, unsigned short cols, string teacher)
{
unsigned short counter = ZERO;
rows--;
while (rows--)
{
counter += StringCompare(&((*ptr_mat).teacher), teacher);
ptr_mat += cols;
}
return (counter);
}
// Ex2
unsigned short TeacherCountOfHoursInWeek(struct study_hours *ptr_mat, unsigned short rows, unsigned short cols, string teacher)
{
unsigned short counter = ZERO;
unsigned short day = cols;
while (day--)
{
counter += TeacherCountOfHoursInDay(ptr_mat++, rows, cols, teacher);
}
return counter;
}
int CountStudentsInSubjectOnDay(struct study_hours *ptr_mat, unsigned short rows, unsigned short cols, unsigned short subject)
{
int counter = ZERO;
rows--;
while (rows--)
{
counter += ((*ptr_mat).subject == subject) ? (*ptr_mat).total_students : ZERO;
ptr_mat += cols;
}
return (counter);
}
// Ex3
int CountStudentsInSubjectOnWeek(struct study_hours *ptr_mat, unsigned short rows, unsigned short cols, unsigned short subject)
{
int total_students = ZERO;
unsigned short days = cols;
while (days--)
{
total_students += CountStudentsInSubjectOnDay(ptr_mat, rows, cols, subject);
}
return (total_students);
}
void main(void)
{
string vec_subjects[MAXSIZE];
}
+67
View File
@@ -0,0 +1,67 @@
#include "PointersLibs.h"
#include <malloc.h>
#define TWO_THOUSAND 2000
#define NINETEEN 1900
struct book
{
string name;
string wrtier;
string company;
int year;
int price;
int id;
};
void AddBook(struct book *ptr_vec, unsigned short vec_length)
{
struct book b;
// I/O book
// Check I/O book - if I/O is ok = do realloc : out from fun
ptr_vec = realloc(ptr_vec, ++(vec_length) * sizeof(struct book));
*(ptr_vec + (vec_length) - ONE) = b;
}
struct book * SearchByName(struct book *ptr_vec, unsigned short vec_length, string *name)
{
while (!StringCompare((*(ptr_vec++)).name, *name) && vec_length--);
return (--ptr_vec);
}
struct book * SearchByWriter(struct book *ptr_vec, unsigned short vec_length, string *writer)
{
while (!StringCompare((*(ptr_vec++)).wrtier, *writer) && vec_length--);
return (--ptr_vec);
}
struct book * SearchByNameAndWriter(struct book *ptr_vec, unsigned short *vec_length, string *name, string *writer)
{
}
struct book * TwentyCentury(struct book *ptr_vec, unsigned short vec_length, struct book *ptr_new_vec)
{
ptr_new_vec = malloc(sizeof(struct book));
unsigned int length = ONE;
unsigned short counter;
for (counter = ZERO; counter < vec_length; counter++)
{
if ((*ptr_vec).year >= 1900 && (*ptr_vec).year >= 2000)
{
*(ptr_new_vec + (length++)) = *ptr_vec;
ptr_new_vec = realloc(ptr_new_vec, sizeof(struct book) * length);
}
ptr_vec++;
}
ptr_new_vec = realloc(ptr_new_vec, sizeof(struct book) * (--length));
return (ptr_new_vec);
}
void main(void)
{
}
File diff suppressed because it is too large Load Diff
+35
View File
@@ -0,0 +1,35 @@
#include "PointersLibs.h"
int SlantSum(int *ptr_mat, unsigned short rows, unsigned short cols)
{
int sum = ZERO;
cols++;
for ( ;rows; rows--)
{
sum += *ptr_mat;
ptr_mat += cols;
}
return (sum);
}
int SlantWithMaxSum(int *ptr_mat, unsigned short rows, unsigned short cols)
{
int max = MainSlantSum(ptr_mat, rows, cols);
int temp;
unsigned short slats;
ptr_mat++;
for (slats = ONE; slats < cols; slats++)
{
temp = SlantSum(ptr_mat++, rows, cols);
max = (temp > max) ? temp : max;
}
return (max);
}
void main(void)
{
}
Binary file not shown.
+56
View File
@@ -0,0 +1,56 @@
#include "PointersLibs.h"
int SumInSlantUntilNegative(int *ptr_mat, unsigned short rows, unsigned short cols)
{
int max = *ptr_mat;
int steps = cols + ONE;
while (rows-- && (*ptr_mat < ZERO))
{
max += *ptr_mat;
ptr_mat += steps;
}
return (max - *ptr_mat);
}
int MaxSumSlant(int *ptr_mat, unsigned short rows, unsigned short cols)
{
int *ptr_max_mat = ptr_mat; // Save the pointer of start max
int max = *ptr_max_mat;
unsigned short steps = cols + ONE;
int *ptr_temp_mat = ptr_mat + steps; // For checking
int temp_max = max,
temp;
rows--;
for (; rows; rows--)
{
temp = temp_max + *ptr_temp_mat;
if (temp < temp_max || temp_max > temp)
{
if (temp_max > max)
{
max = temp_max;
ptr_max_mat = ptr_temp_mat;
}
temp_max = ZERO;
}
temp_max += *ptr_temp_mat;
ptr_temp_mat += steps;
}
}
void main(void)
{
int mat[4][5] = {
{1,2,3,4,5},
{2,3,4,5,6},
{3,4,-1,6,7},
{4,5,6,7,8}
};
printf("%d\n", MaxSumInSlant(mat, 4, 5));
}
+1925
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
+72
View File
@@ -0,0 +1,72 @@
#include "Lib.h"
//---------------------------------------------------------------------------------------
// Exc1a
// -----
//
// General : The function checks when the order in the stack is turn over.
//
// Parameters : s - A stack with numbers inside.(in)
//
// Return Value : The value in the stack when the order is turned over.
//
//---------------------------------------------------------------------------------------
// Programer : Cohen Idan
// Student No. : 211675038
// Date : 05.12.2019
//---------------------------------------------------------------------------------------
int SectionOne(stack * sk)
{
stack temp_sk;
InitializeStack(&temp_sk);
CopyStack(&temp_sk, sk);
int last_number = PopStack(&temp_sk).int_;
int this_number = PopStack(&temp_sk).int_;
while (this_number >= last_number)
{
last_number = this_number;
this_number = PopStack(&temp_sk).int_;
}
return (this_number);
}
//---------------------------------------------------------------------------------------
// Exc1b
// -----
//
// General : The function checks when the order in the stack is turn over.
//
// Parameters : s - A stack with numbers inside.(in)
//
// Return Value : The position in the stack when the order is turned over.
//
//---------------------------------------------------------------------------------------
// Programer : Cohen Idan
// Student No. : 211675038
// Date : 05.12.2019
//---------------------------------------------------------------------------------------
int SectionOne(stack * sk)
{
stack temp_sk;
InitializeStack(&temp_sk);
CopyStack(&temp_sk, sk);
unsigned int counter = ZERO;
int number = SectionOne(&temp_sk);
while (PopStack(&temp_sk).int_ != number)
{
counter++;
}
return (counter);
}
void main(void)
{
stack s;
InitializeStack(&s);
Data_Type num1 = {.int_ = 4}, num2 = {.int_ = 5}, num3 = {.int_ = 6};
PushStack(&s, num1);
PushStack(&s, num2);
PushStack(&s, num3);
}
View File
+62
View File
@@ -0,0 +1,62 @@
#include "Lib.h"
void DeleteItem(stack * sk, Data_Type item)
{
Data_Type temp_item;
stack temp_sk;
InitializeStack(&temp_sk);
while (!IsEmptyStack(sk))
{
temp_item = PopStack(sk);
if (temp_item.int_ != item.int_)
{
PushStack(&temp_sk, temp_item);
}
}
while (!IsEmptyStack(&temp_sk))
{
PushStack(sk, PopStack(&temp_sk));
}
}
void DeleteDuplicates(stack * sk)
{
Data_Type item;
stack temp_sk;
InitializeStack(&temp_sk);
while (!IsEmptyStack(sk))
{
item = PopStack(sk);
DeleteItem(sk, item);
PushStack(&temp_sk, item);
}
while (!IsEmptyStack(&temp_sk))
{
PushStack(sk, PopStack(&temp_sk));
}
}
//---------------------------------------------------------------------------------------
// Exc3
// ----
//
// General : The function delete the duplicate numbers from the stack.
//
// Parameters : s - A stack with numbers inside.(in)
//
// Return Value : The stack without the duplicated numbers.
//
//---------------------------------------------------------------------------------------
// Programer : Cohen Idan
// Student No. : 211675038
// Date : 05.12.2019
//---------------------------------------------------------------------------------------
void main(void)
{
stack s;
InitializeStack(&s);
Data_Type num1 = {.int_ = 4}, num2 = {.int_ = 5}, num3 = {.int_ = 6};
PushStack(&s, num1);
PushStack(&s, num2);
PushStack(&s, num3);
}
+56
View File
@@ -0,0 +1,56 @@
#include "Lib.h"
#define MAX 21
typedef struct
{
string name;
unsigned int amount;
} VegBox;
//---------------------------------------------------------------------------------------
// AddBox
// -------
//
// General : The function added new box to the tower of boxes in some Circumstances.
//
// Parameters : Tower - A stack with boxes inside.(in)
// box - A item from the type VegBox that needed to be add to the tower.
//
// Return Value : None.
//
//---------------------------------------------------------------------------------------
// Programer : Cohen Idan
// Student No. : 211675038
// Date : 05.12.2019
//---------------------------------------------------------------------------------------
void AddBox(stack * sk, VegBox vb)
{
Data_Type item = PopStack(sk);
Data_Type new_item;
stack temp_sk;
InitializeStack(&temp_sk);
while (!IsEmptyStack(sk) && !StringCompare((*(VegBox *)(item.pointer)).name, vb.name))
{
item = PopStack(sk);
PushStack(&temp_sk, item);
}
if (!StringCompare((*(VegBox *)(item.pointer)).name, vb.name))
{
while ((*(VegBox *)(item.pointer)).amount++ < MAX && vb.amount-- > ZERO);
}
while (!IsEmptyStack(&temp_sk))
{
PushStack(sk, PopStack(&temp_sk));
}
if (vb.amount > ZERO)
{
*(VegBox * )new_item.pointer = vb;
PushStack(sk, new_item);
}
}
void main(void)
{
}

Some files were not shown because too many files have changed in this diff Show More