二级指针赋值

#include <stdio.h>
#include <Windows.h>

#pragma warning(disable:4996)

char name[100];

void modify(char ** a)
{
   //char* name = new char[100];
  strcpy(name, "1");
  *a = name;
}


int main()
{
  char *b;

  modify(&b);

  printf("%s", b);

  return 0;
}

 更新:

#include <stdio.h>
#include <stdlib.h>

#pragma warning(disable:4996)

void verify(char** em)
{
    char *z = *em;

    while (*z)
    {
        printf("%c", *z++);
    }

    z = *em;

    while (*z != '\n')
    {
        if (*z == 'a')
        {
            printf("present");
        }
        else
        {
            printf("not present");
        }
        z++;
    }
}

int main()
{
    int count = 0;
    char *email = (char*)malloc(sizeof(char) * 100);

    printf("enter the email id\n");
    scanf("%100s", email);

    char *it = email;
    while (*it)
    {
        printf("%c", *it++);
    }

    verify(&email);

    free(email);
    return 0;
}

可以不使用二级指针传址

void verify(char* em)
{
    char *z = em;

    while (*z)
    {
        printf("%c", *z++);
    }

    z = em;

    while (*z != '\n')
    {
        if (*z == 'a')
        {
            printf("present");
        }
        else
        {
            printf("not present");
        }
        ++z;
    }
}

int main()
{
    int count = 0;
    char *email = (char*)malloc(sizeof(char) * 100);

    printf("enter the email id\n");
    scanf("%100s", email);

    char *it = email;
    while (*it)
    {
        printf("%c", *it++);
    }

    verify(email);

    free(email);
    return 0;
}

 

posted @ 2019-09-06 18:19  strive-sun  阅读(790)  评论(0编辑  收藏  举报