Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
- #define LENGTH 50
- void PrintArray(int *array, int length);
- void push(char x);
- int pop(void);
- bool search(int number);
- void PrintStack(void);
- int stack[256];
- int count = 0;
- typedef struct Point{
- int x;
- int y;
- int z;
- } Point;
- void PrintPoint(Point *point);
- void SetPoint(Point *point, int value);
- void BubbleSortChars(char *array, int length);
- int main(void){
- srand(1);
- Point point = { .x = 5, .y = 10 };
- Point *pointer = &point;
- printf("%lu\n", sizeof(point));
- PrintPoint(&point);
- SetPoint(&point, 0);
- PrintPoint(&point);
- char *s[5] = {"Hello", " ", "world", ".", "\n"};
- for(int i = 0; i < 5; i++){
- printf("%s", s[i]);
- }
- for(int i = 3; i >= 0; i--){
- printf("%s", s[i]);
- }
- printf("\n");
- int number = rand();
- char characters[LENGTH];
- for(int i = 0; i <= LENGTH - 1; ++i){
- number = rand() % ('z' - 'a');
- number += 'a';
- characters[i] = number;
- }
- characters[LENGTH-1] = '\0';
- printf("%s\n", characters);
- BubbleSortChars(characters, LENGTH);
- printf("%s\n", characters);
- char current;
- printf("(");
- for(int i = 0; i < LENGTH; ++i){
- printf("%c", characters[i]);
- current = characters[i];
- if(current != characters[i+1] && i < LENGTH-2){
- printf(")(");
- }
- }
- printf(")");
- printf("\n");
- char cur = 0;
- int counts[LENGTH] = {0};
- int slot = 0;
- for(int i = 1; i < LENGTH; ++i){
- cur = characters[i-1];
- if(characters[i] == cur) {
- counts[slot]++;
- } else {
- slot++;
- }
- }
- for(int i = 0; i < slot; ++i){
- counts[i]++;
- if(i < slot-1){
- printf("%i,", counts[i]);
- } else {
- printf("%i", counts[i]);
- }
- }
- }
- void BubbleSortChars(char *array, int length){
- for(int i = 0; i < length-1; ++i){
- for(int j = 0; j < length-2; ++j){
- if(array[j] > array[j+1]) {
- char temp = array[j+1];
- array[j+1] = array[j];
- array[j] = temp;
- }
- }
- }
- }
- void PrintPoint(Point *point){
- printf("%d, %d, %d\n", point->x, point->y, point->z);
- }
- void SetPoint(Point *point, int value){
- point->x = value;
- point->y = value;
- point->z = value;
- }
- void PrintArray(int *array, int length){
- for(int i = 0; i < length; i++){
- printf("%i,", *(array+i));
- }
- printf("\n");
- }
- void push(char x){
- if(count == 256){
- fprintf(stderr, "Stack is full.\n");
- } else {
- stack[count] = x;
- count++;
- }
- }
- int pop(void){
- if(count == 0){
- fprintf(stderr, "Stack is empty.\n");
- exit(1);
- } else {
- int res = stack[count-1];
- count--;
- return res;
- }
- }
- bool search(int number){
- for(int i = count; i > 0; i--){
- if(stack[i] == number){
- return true;
- }
- }
- return false;
- }
- void PrintStack(void){
- printf("[");
- for(int i = 0; i < count; i++){
- printf("%X", stack[i]);
- if(i != count-1){
- printf(",");
- }
- }
- printf("]");
- printf("\n");
- }
Add Comment
Please, Sign In to add comment