Learning journal day two

Posted by Stevan on Tue, 07 Jan 2020 02:30:18 +0100

Actual combat of Suqian project

Learning log name: Huang Zhiheng date: September 4, 2018

Today's learning tasks
In stack out stack empty stack

Task completion today

(specify whether the task of this day is completed as planned and the amount of code developed)
P1

#include<stdio.h>
#include<string.h>
#define N 50

void strRev(char *s)
{
        char temp;
        char *end = s + strlen(s) -1;
        while (end > s)
        {
                temp = *s;
                *s = *end;
                *end = temp;
                --end;
                ++s;
        }
}

int main()
{
        char s[N];

        printf("Enter string!\n");
        fgets(s,N,stdin);
        strRev(s);

        printf("The strRcv string!");
        puts(s);

        return 0;
}

P2

#include<stdio.h>

int fun2(int num);
int fun16(int num);
int fun8(int num);

int main()
{
    int num,kind;

    printf("Enter the number:\n");
    scanf("%d",&num);
    printf("what kind of number do you want to change(2,16,8):\n");
    scanf("%d",&kind);

    if(kind == 2)
    {
        fun2(num);
    }
    else if(kind == 16)
    {
        fun16(num);
    }
    else if(kind == 8)
    {
        fun8(num);
    }
    else
    {
        printf("error!\n");
    }
    return 0;
}

int fun2(int num)
{
    int s[32]={0};
    int i,n=0;
    while(num != 0)
    {
        s[n++]=num%2;
        num=num/2;
    }
    printf("Binary numbers are:");
    for(i=n -1;i>=0;i--)
    {
        printf("%d",s[i]);

    }
    printf("\n");
    return 0;
}

int fun16(int num)
{

    int s[32]={0};
    int i,n=0;
    while(num != 0)
    {
        s[n++]=num%16;
        num=num/16;
    }
    printf("Hexadecimal number is:");
    for(i=n -1;i>=0;i--)
    {
        printf("%d",s[i]);

    }
    printf("\n");
    return 0;
}

int fun8(int num)
{

    int s[32]={0};
    int i,n=0;
    while(num != 0)
    {
        s[n++]=num%8;
        num=num/8;
    }
    printf("Octal number is:");
    for(i=n -1;i>=0;i--)
    {
        printf("%d",s[i]);

    }
    printf("\n");
    return 0;
}

P3

#include<stdio.h>
#include<string.h>
int main()
{
    char a[100];
    printf("Please enter a string\n");
    scanf("%s",a);
    char *c =a;
    char b[10];
    printf("Please input substring\n");
    scanf("%s",b);
    char *d=b;
    int n;
    int num=0;
    n=strlen(d);
    while(strlen(c)>0)
    {
        if(strncmp(c,d,n)==0)
        {
            num++;
            c+=n;
        }
        else
        {
            c++;
        }
    }
    printf("%d\n",num);
    return 0;
}

P4

#include<stdio.h>
#include<string.h>
#define N 50

void strRev(char *s)
{
    char temp;
    char *end = s + strlen(s) -1;
    while (end > s)
    {
        temp = *s;
        *s = *end;
        *end = temp;
        --end;
        ++s;
    }
}

int main()
{
    char s[N];

    printf("Enter string!\n");
    fgets(s,N,stdin);
    strRev(s);

    printf("The strRcv string!");
    puts(s);

    return 0;
}

P5

#include <stdio.h>

int find(char *s,char *a,char *b);

int main()
{
    char s[100],a[100],b[100];        //Define three arrays to hold strings and first and last strings

 printf("Enter the long string : \n");        //Prompt user for string
 scanf("%s",s);
 printf("Enter the head string : \n");
 scanf("%s",a);
 printf("Enter the tail string : \n");
 scanf("%s",b);

 find(s,a,b);        //Calling function

    return 0;
}

int find(char *s,char *a,char *b)
{
 int head,tail;        //Define head and tail node position variables
 int i = 0,j = 0,k = 0,flag = 0;        //Define loop variables i,j,k and flag

 while(s[i] != '\0') 
 {
  if((s[i] == a[j]) && !flag)        //When a character is equal to the header string, continue to judge whether it is the header string
  {
   head = i;        //Assign string position to header node position
      while((s[i] == a[j]) && s[i] != '\0')        //Enter loop judgment header string
      {
       i++;
       j++;
    flag = 1;       
      }
  }

  if((a[j] == '\0') && flag)        //When the traversal of the header string ends and the flag bit changes to 1, the header string is considered to have been found
  {
      while((s[i] == b[k]) && s[i] != '\0')        //Enter the loop judgment tail string
      {

Summary of problems in today's development
That's all right.

Open issues today
No,

Today's development gains

Many thieves

Self evaluation
nice

(whether to complete the established tasks according to the development specifications, the areas to be improved, the effect of cooperation with others, etc.)

Other

Topics: P4