鱼C论坛

 找回密码
 立即注册
楼主: 冰点雨

[吹水] 今天开始学习编程,立帖为证!

  [复制链接]
发表于 2013-5-1 21:32:11 | 显示全部楼层
坚持坚持
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-5-1 22:00:55 | 显示全部楼层
啊, 楼主加油哇, 我也是自学的。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2013-5-2 00:57:27 | 显示全部楼层
#include <stdio.h>
#include <string.h>

void main()
{


struct student
{
        long int num;
        char name [20];
        char scx;
        char sex;
        float score;

}stu_1, *p;
p=&stu_1;
stu_1.num=89101;
strcpy(stu_1.name,"LiLin");
(*p).sex='M';
p->score=89.5;

printf("\nNo:%d\nname:%s\nsex:%c\nscore:%f\n",
           (*p).num,p->name,stu_1.sex,p->score);


}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2013-5-3 02:08:33 | 显示全部楼层
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

#define LEN sizeof(struct student)  // student结构的大小

//struct student *creat();            //创建链表
void print(struct student *head);   //打印链表

struct student
{
      int num;
      float score;
      struct student *next;
}*creat();

int n; //全局变量,用来记录存放了多少数据。

void main()
{
     struct student *stu;

      stu = creat();
      print( stu );

      printf("\n\n");
      system("pause");
}

struct student *creat()
{
      struct student *head;
      struct student *p1, *p2;
  
      p1 = p2 = (struct student *)malloc(LEN);  // LEN是student结构的大小
       
                printf("%d\n",LEN);

      printf("Please enter the num :");
                scanf("%d", &p1->num);
      printf("Please enter the score :");
      scanf("%f", &p1->score);

      head = NULL;     
      n = 0;   
      
      while( 0 != p1->num )
      {
            n++;
            if( 1 == n )
            {
                  head = p1;                 
            }
            else
            {
                  p2->next = p1;
            }

            p2 = p1;

            p1 = (struct student *)malloc(LEN);

            printf("\nPlease enter the num :");
            scanf("%d", &p1->num);
            printf("Please enter the score :");
            scanf("%f", &p1->score);
      }

      p2->next = NULL;

      return head;
}

void print(struct student *head)
{
      struct student *p;
      printf("\nThere are %d records!\n\n", n);

      p = head;
      if( NULL != head )
      {
            do
            {
                  printf("学号为 %d 的成绩是: %f\n", p->num, p->score);
                  p = p->next;
            }while( NULL != p );
      }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2013-5-4 07:42:53 | 显示全部楼层
#include <stdio.h>
#include <stdlib.h>

void main()
{
      FILE *fp;
      char ch, filename[20];

      printf("Please input the filename you want to write: ");
      scanf("%s", filename);
      
      if( !(fp = fopen(filename, "r")))
      {
            printf("Cannot open the file!\n");
            exit(0);   // 终止程序
      }

      while( ch != EOF )   // ctrl + z
      {
            ch = fgetc(fp);
            putchar(ch);
      }

      fclose(fp);
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-5-4 10:06:25 | 显示全部楼层
不可能吧我猜你不懂指针结构体
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2013-5-4 14:26:04 | 显示全部楼层

指针 完全掌握那是不可能滴 ; 但是理解那几种形式还是做到了 结构体嘛   其实链表   就是结构体加指针;
我们感觉难是因为问题复杂 化了   返璞归真,   拆开来看问题就简单多了;  看来看去 其实就是组合;
    变量,常量  赋值 ,模块化 顺寻结构 一路来再到指针 结构体··;
好比指针; 如果不看星号  他就是 一个变量;   其实看视频别心浮气躁; 像指针我每个 看5-10遍 ; 一天看12小时··  功到自然成···   
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2013-5-5 07:22:46 | 显示全部楼层
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

#define LEN sizeof(struct student)  // student结构的大小

struct student *creat();   //创建链表
struct student *del( struct student *head, int num);  //del函数用于删除结点, *head即链表
                                                      //的头指针, num是要删除的结点num。

void print(struct student *head);   //打印链表

struct student
{
      int num;
      float score;
      struct student *next;
};

int n; //全局变量,用来记录存放了多少数据。

void main()
{
      struct student *stu, *p;
      int n;

      stu = creat();
      p = stu;
      print( p );

      printf("Please enter the num to delete: ");
      scanf("%d", &n);
      print( del(p, n) );
      
      printf("\n\n");
      system("pause");
}

struct student *creat()
{
      struct student *head;
      struct student *p1, *p2;
  
      p1 = p2 = (struct student *)malloc(LEN);  // LEN是student结构的大小

      printf("Please enter the num :");
      scanf("%d", &p1->num);
      printf("Please enter the score :");
      scanf("%f", &p1->score);

      head = NULL;     
      n = 0;   
      
      while( p1->num )
      {
            n++;
            if( 1 == n )
            {
                  head = p1;                 
            }
            else
            {
                  p2->next = p1;
            }

            p2 = p1;
            p1 = (struct student *)malloc(LEN);

            printf("\nPlease enter the num :");
            scanf("%d", &p1->num);
            printf("Please enter the score :");
            scanf("%f", &p1->score);
      }

      p2->next = NULL;

      return head;
}

void print(struct student *head)
{
      struct student *p;
      printf("\nThere are %d records!\n\n", n);

      p = head;
      if( head )
      {
            do
            {
                  printf("学号为 %d 的成绩是: %f\n", p->num, p->score);
                  p = p->next;
            }while( p );
      }
}

struct student *del( struct student *head, int num)
{
      struct student *p1, *p2;
      
      if( NULL == head )
      {
            printf("\nThis list is null!\n");
            goto end;
      }

      p1 = head;
      while( p1->num != num && p1->next != NULL)
      {
            p2 = p1;
            p1 = p1->next;
      }
      if( num == p1->num )
      {
            if( p1 == head )
            {
                  head = p1->next;
            }
            else
            {
                  p2->next = p1->next;
            }

            printf("Delete No: %d succeed!\n", num);
            n = n-1;
      }
      else
      {
            printf("%d not been found!\n", num);
      }

end:
      return head;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-5-5 08:47:21 | 显示全部楼层
楼主加油,鱼C加油!我们都看好你哦!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-5-5 08:53:46 | 显示全部楼层
楼主要是初中文凭那里要加油了,如果你没有充分的想像力,那你学的也是白干
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-5-5 09:23:07 | 显示全部楼层
激动人心,无法言表!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-5-5 09:56:33 | 显示全部楼层
fire8223069 发表于 2013-5-5 08:47
楼主加油,鱼C加油!我们都看好你哦!

强烈支持楼主ing…我太笨了我学了几个月了也就这样
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-5-5 10:22:30 | 显示全部楼层
我只是路过打酱油的。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-5-5 22:44:41 | 显示全部楼层
强烈支持楼主ing……
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-5-5 22:45:59 | 显示全部楼层
强烈支持楼主ing……
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2013-5-6 00:45:28 | 显示全部楼层
栈 的原理    先进 后出   指令PUSH   pop
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2013-5-7 02:31:24 | 显示全部楼层
mov ax,236
mov cx,122
s :add ax,ax
loop s
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2013-5-8 03:24:38 | 显示全部楼层
assume cs:code
code segment
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
mov bx,0
mov ax,0
mov cx,8
s:add ax,cx:[bx]
add bx,2
loop s
mov ax,4c00h
int 21h
code ends
end
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-5-8 21:52:05 | 显示全部楼层
励志贴啊,好贴·
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2013-5-9 01:43:48 | 显示全部楼层
codesg segment
start :mov ax,datasg
mov si,0
mov cx,8
s: mov ax,0[si]
mov 16[si],ax
add si,2
loop s
mov ax,4c00h
int 21h
codesg ends
end start
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-26 00:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表