fgets, fputs

 
#include<stdio.h>
#define LEN 20

typedef struct student
{
 char name[20];
 char stdnum[20];
 char school[20];
 char major[20];
 int year;
}Student;

void ShowStudentInfo(Student *sptr);


int main(void)
{
 Student arr[3];
 int i;

 for(i=0;i<3;i++)
 {
  fputs("이름: ",stdout); fgets(arr[i].name,LEN,stdin);
  fputs("학번: ",stdout); fgets(arr[i].stdnum,LEN,stdin);
  fputs("학교: ",stdout); fgets(arr[i].school,LEN,stdin);
  fputs("전공: ",stdout); fgets(arr[i].major,LEN,stdin);
  fputs("학년: ",stdout); scanf("%d",&arr[i].year);

  while(getchar() != '\n'); //enter이면 빠져나간다. 따라서 enter가 올때까지 읽어들여서 입력버퍼에 있는 값을 빼냄..
 }

 ShowStudentInfo(arr);
}

void ShowStudentInfo(const Student *sptr)
{
 int i;
 for(i=0;i<3;i++)
 {
  printf("이름 %s  ",sptr[i].name);
  printf("학번 %s  ",sptr[i].stdnum);
  printf("학교 %s  ",sptr[i].school);
  printf("전공 %s  ",sptr[i].major);
  printf("학년 %d  ",sptr[i].year);

  printf("\n");
 }
}

 

 


#include<stdio.h>


int main(void)

{


FILE * fp=fopen("c:\\project\\mystory.txt","wt");


if(fp==NULL)

{

puts("파일 오픈 실패!");

return -1;

}


fputs("#이름: 윤성우\n",fp);

fputs("#주민번호: 900208-10122589\n",fp);

fputs("#전화번호: 010-1111-2222\n",fp);


  fclose(fp);

return 0;

}


#include<stdio.h>

int main(void)

{

FILE * fp=fopen("c:\\project\\mystory.txt","at");


if(fp==NULL)

{

puts("파일 오픈 실패!");

return -1;

}


fputs("#즐겨먹는 음식: 짬뽕, 탕수육\n",fp);

fputs("#취미: 축구\n",fp);

  fclose(fp);

return 0;

}


#include<stdio.h>

int main(void)

{

char str[30];

int i=0;

FILE * fp=fopen("c:\\project\\mystory.txt","rt");


if(fp==NULL)

{

puts("파일 오픈 실패!");

return -1;

}

for(i=0;i<5;i++){

fgets(str, sizeof(str),fp);

printf("%s", str);

}


fclose(fp);

return 0;

}

 BulletCtrl 




using UnityEngine;

using System.Collections;


public class BulletCtrl : MonoBehaviour {

public Transform Tr;

public float speed = 500.0f;

public float damage = 10.0f;

private Vector3 spawnPoint;

public float fireRange = 300.0f;


// Use this for initialization

void Start () {

Tr = this.GetComponent<Transform>();

spawnPoint = Tr.position;

}

// Update is called once per frame

void Update () {

Tr.Translate(Vector3.forward * Time.deltaTime * speed);

if((spawnPoint - Tr.position).sqrMagnitude > fireRange)

{

RemoveBullet();

}

}

void RemoveBullet()

{

StartCoroutine(this.DestroyBullet());

}

IEnumerator DestroyBullet()

{

Destroy(this.gameObject);

yield return null;

}

}

 

 

 

 

 

 

'C' 카테고리의 다른 글

Visual Studio 단축키  (0) 2013.10.01
구구단(입력된 단수부터 출력)  (0) 2013.09.02

+ Recent posts