JAVA 파일 검색 코드

Programming/JAVA,JSP 2013. 12. 28. 17:03 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.io.File;

import java.io.IOException;

 

public class FileTest {

           public static void main(String[] args) throws IOException {

                     String name = "c:/";                 

                     searchDirectory(name);

                    

 

           }

 

           static void searchDirectory(String name) {

                     File dir = new File(name);

                     String[] fileNames = dir.list();

                     for (String s : fileNames) {

                               

                                File f = new File(name + "/" + s); // 절대 경로로 이름을 주어야 함

                                if( f.isHidden())

                                {

                                          continue;

                                }

                                System.out.println("===============================");

                                System.out.println("이름: " + f.getName());

                                if( f.getName().equals("c01.bmp"))

                                          //

                                          if(f.getName().contains("c01"))

                                {

                                          System.err.println("Find Out!!!!");

                                          System.exit(0);

                                }

                                System.out.println("경로: " + f.getPath());

                                if( f.isDirectory() )

                                {

                                          searchDirectory(name + "/" + s);

                                }

                                System.out.println("===============================");

                     }

           }

}

 

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA Calendar #2  (0) 2013.12.31
Calendar #1  (0) 2013.12.31
JAVA GUI 계산기 소스코드  (0) 2013.12.22
JAVA 소수를 구하는 프로그램 GUI #2  (0) 2013.12.21
JAVA 소수를 판단하는 GUI 프로그램  (0) 2013.12.21

Visual Studio 2010 Express Version

Programming/C,CPP,CS 2013. 12. 28. 11:30 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
http://wasni12n.blog.me/196139266

 

JAVA GUI 계산기 소스코드

Programming/JAVA,JSP 2013. 12. 22. 17:55 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


import javax.swing.JButton;


/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */


/**

 * 

 * @author Administrator

 */

public class NewJFrame extends javax.swing.JFrame implements ActionListener {


/**

* Creates new form NewJFrame

*/

public NewJFrame() {

initComponents();

toDo();

}


private void toDo() {

// TODO Auto-generated method stub

jButton2.addActionListener(this);

jButton3.addActionListener(this);

jButton4.addActionListener(this);

jButton5.addActionListener(this);

jButton6.addActionListener(this);

jButton7.addActionListener(this);

jButton8.addActionListener(this);

jButton9.addActionListener(this);

jButton10.addActionListener(this);

jButton13.addActionListener(this);

jButton14.addActionListener(this);

jButton15.addActionListener(this);

jButton16.addActionListener(this);

jButton17.addActionListener(this);

jButton18.addActionListener(this);

}


@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {


jButton2 = new javax.swing.JButton();

jTextField3 = new javax.swing.JTextField();

jButton3 = new javax.swing.JButton();

jButton4 = new javax.swing.JButton();

jButton7 = new javax.swing.JButton();

jButton5 = new javax.swing.JButton();

jButton6 = new javax.swing.JButton();

jButton8 = new javax.swing.JButton();

jButton9 = new javax.swing.JButton();

jButton10 = new javax.swing.JButton();

jButton13 = new javax.swing.JButton();

jButton14 = new javax.swing.JButton();

jButton15 = new javax.swing.JButton();

jButton16 = new javax.swing.JButton();

jButton17 = new javax.swing.JButton();

jButton18 = new javax.swing.JButton();

jToggleButton1 = new javax.swing.JToggleButton();


setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);


jTextField3.setText("");


jButton2.setText("1");


jButton3.setText("2");


jButton4.setText("3");


jButton5.setText("4");


jButton6.setText("5");


jButton7.setText("6");


jButton8.setText("7");


jButton9.setText("8");


jButton10.setText("9");


jButton13.setText("0");


jButton14.setText("+");


jButton15.setText("/");


jButton16.setText("x");


jButton17.setText("-");


jButton18.setText("=");


jToggleButton1.setText("jToggleButton1");


javax.swing.GroupLayout layout = new javax.swing.GroupLayout(

getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(layout

.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jTextField3)

.addGroup(

layout.createSequentialGroup()

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.TRAILING)

.addGroup(

layout.createSequentialGroup()

.addComponent(

jButton5)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton6)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton7))

.addGroup(

layout.createSequentialGroup()

.addComponent(

jButton2)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton3)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton4)))

.addGroup(

layout.createSequentialGroup()

.addComponent(

jButton9)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(

jButton13)

.addGroup(

layout.createSequentialGroup()

.addComponent(

jButton10)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton8)))))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createSequentialGroup()

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(

jButton16)

.addComponent(

jButton15))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton18))

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(

jButton17)

.addComponent(

jButton14)))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED,

javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE)

.addComponent(jToggleButton1,

javax.swing.GroupLayout.PREFERRED_SIZE,

70,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap()));

layout.setVerticalGroup(layout

.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createSequentialGroup()

.addComponent(jTextField3,

javax.swing.GroupLayout.PREFERRED_SIZE,

70,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING,

false)

.addGroup(

layout.createSequentialGroup()

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(

jButton2)

.addComponent(

jButton3)

.addComponent(

jButton4))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(

jButton5)

.addComponent(

jButton6)

.addComponent(

jButton7))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(

jButton9)

.addComponent(

jButton10)

.addComponent(

jButton8))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton13))

.addGroup(

layout.createSequentialGroup()

.addComponent(

jButton14)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton17)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton16)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(

jButton15))

.addComponent(

jButton18,

javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE)

.addComponent(

jToggleButton1,

javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE))

.addContainerGap(

javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE)));


pack();

}// </editor-fold>


public static void main(String args[]) {

/* Set the Nimbus look and feel */

// <editor-fold defaultstate="collapsed"

// desc=" Look and feel setting code (optional) ">

/*

* If Nimbus (introduced in Java SE 6) is not available, stay with the

* default look and feel. For details see

* http://download.oracle.com/javase

* /tutorial/uiswing/lookandfeel/plaf.html

*/

try {

for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager

.getInstalledLookAndFeels()) {

if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

}

}

} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

java.util.logging.Level.SEVERE, null, ex);

}

// </editor-fold>


/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new NewJFrame().setVisible(true);

}

});

}


// Variables declaration - do not modify

private javax.swing.JButton jButton10;

private javax.swing.JButton jButton13;

private javax.swing.JButton jButton14;

private javax.swing.JButton jButton15;

private javax.swing.JButton jButton16;

private javax.swing.JButton jButton17;

private javax.swing.JButton jButton18;

private javax.swing.JButton jButton2;

private javax.swing.JButton jButton3;

private javax.swing.JButton jButton4;

private javax.swing.JButton jButton7;

private javax.swing.JButton jButton5;

private javax.swing.JButton jButton6;

private javax.swing.JButton jButton8;

private javax.swing.JButton jButton9;

private javax.swing.JTextField jTextField3;

private javax.swing.JToggleButton jToggleButton1;


// End of variables declaration

@Override

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

if (arg0.getSource() == jButton2) {

jTextField3.setText(jTextField3.getText() + 1);

} else if (arg0.getSource() == jButton3) {

jTextField3.setText(jTextField3.getText() + "2");

} else if (arg0.getSource() == jButton4) {

jTextField3.setText(jTextField3.getText() + "3");

} else if (arg0.getSource() == jButton7) {

jTextField3.setText(jTextField3.getText() + "4");

} else if (arg0.getSource() == jButton5) {

jTextField3.setText(jTextField3.getText() + "5");

} else if (arg0.getSource() == jButton6) {

jTextField3.setText(jTextField3.getText() + "6");

} else if (arg0.getSource() == jButton8) {

jTextField3.setText(jTextField3.getText() + "7");

} else if (arg0.getSource() == jButton9) {

jTextField3.setText(jTextField3.getText() + "8");

} else if (arg0.getSource() == jButton10) {

jTextField3.setText(jTextField3.getText() + "9");

} else if (arg0.getSource() == jButton13) {

jTextField3.setText(jTextField3.getText() + "0");

} else if (arg0.getSource() == jButton14) {// +

tempValue = Integer.parseInt(jTextField3.getText());

operator = '+';

jTextField3.setText("");

} else if (arg0.getSource() == jButton15) {// /

tempValue = Integer.parseInt(

jTextField3.getText());

operator = '/';

jTextField3.setText("");

} else if (arg0.getSource() == jButton16) {// x

tempValue = Integer.parseInt(jTextField3.getText());

operator = '*';

jTextField3.setText("");

} else if (arg0.getSource() == jButton17) {// -

tempValue = Integer.parseInt(jTextField3.getText());

operator = '-';

jTextField3.setText("");

} else if (arg0.getSource() == jButton18) {// -

int tempValue2 = Integer.parseInt(

jTextField3.getText());

int resultValue = 0;

if (operator == '+') {

resultValue = tempValue + tempValue2;

} else if (operator == '-') {

resultValue = tempValue - tempValue2;

} else if (operator == '*') {

resultValue = tempValue * tempValue2;

} else if (operator == '/') {

resultValue = tempValue / tempValue2;

}

jTextField3.setText("" + resultValue);

}

}


int tempValue;

char operator;

}



'Programming > JAVA,JSP' 카테고리의 다른 글

Calendar #1  (0) 2013.12.31
JAVA 파일 검색 코드  (0) 2013.12.28
JAVA 소수를 구하는 프로그램 GUI #2  (0) 2013.12.21
JAVA 소수를 판단하는 GUI 프로그램  (0) 2013.12.21
JAVA 버블 정렬  (0) 2013.11.30

CPP 함수 실습

실습과제 모음 2013. 12. 22. 12:57 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>

using namespace std;


int isPrimeNumber(int number);


int main()

{

int a = 3;

int result = isPrimeNumber(a);

if(result == 0)

{

cout << "a는 소수 입니다" << endl;

}

else

{

cout << "a는 소수가 아닙니다" << endl;

}

return 0;

}

int isPrimeNumber(int number)

{

// 계산

// 소수 : 1과 나 만으로 나누어 떨어지는 수

// 소수 : x %  1  == 0

//  x %  2  == ?

//  x % ... == ?

//  x % x-2 == ?

//  x % x-1 == ?

//        x %  x  == 0

}

'실습과제 모음' 카테고리의 다른 글

반복문 실습 별찍기  (0) 2013.12.31
실습과제 모음  (0) 2013.12.31
달력 만들기 실습 결과  (0) 2013.12.15
달력 만들기 실습  (1) 2013.12.15
게시판에 간단한 채팅방 만들기  (0) 2013.11.28
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

 

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

 

class MyFrame extends JFrame {

   private JButton button;

   private JTextField text, result;

 

   public MyFrame() {

       setSize(300, 130);

       setTitle("제곱 계산하기");

   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 

       ButtonListener listener = new ButtonListener(); // 리스너 객체 생성

 

       JPanel panel = new JPanel();

       panel.add(new JLabel("숫자 입력: ")); // 레이블 생성

       text = new JTextField(15); // 컬럼수가 15 텍스트 필드 생성

       text.addActionListener(listener); // 텍스트 필드에 리스너 연결

       panel.add(text);

 

       panel.add(new JLabel("제곱한 : "));

       result = new JTextField(15); // 결과를 나타낼 텍스트 필드

       result.setEditable(false); // 편집 불가 설정

       panel.add(result);

       button = new JButton("OK");

       button.addActionListener(listener);

       panel.add(button);

       add(panel);

       setVisible(true);

   }

 

   // 텍스트 필드와 버튼의 액션 이벤트 처리

   private class ButtonListener implements ActionListener {

       public void actionPerformed(ActionEvent e) {

          if (e.getSource() == button || e.getSource() == text) {

             String name = text.getText();

             int value = 0;

             try {

                value = Integer.parseInt(name);

 

                 boolean isPrimeNumber = false;

 

                 // 계산

                 int count = 0;

                 for (int i = 1; i <= value; i++) {

                    // 계산

                    if (value % i == 0) {

                       count++;

                    }

 

                 }

 

                 if (count == 2) {

                    isPrimeNumber = true;

                 }

 

                 if (isPrimeNumber) {

                    result.setText("소수입니다.");

                 } else {

                    result.setText("소수가 아닙니다.");

                 }

            } catch (NumberFormatException e1) {

                 result.setText("숫자를 입력해주세요!!");

             }

             text.requestFocus();

          }

       }

   }

}

 

public class TextFieldTest extends JFrame {

   public static void main(String[] args) {

       new MyFrame();

   }

}

 

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 파일 검색 코드  (0) 2013.12.28
JAVA GUI 계산기 소스코드  (0) 2013.12.22
JAVA 소수를 판단하는 GUI 프로그램  (0) 2013.12.21
JAVA 버블 정렬  (0) 2013.11.30
JAVA JTable 실습 예제  (0) 2013.08.24
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import javax.swing.*;

import java.awt.event.*;

 

class MyFrame extends JFrame {

       private JButton button;

       private JTextField text, result;

 

       public MyFrame() {

             setSize(300, 130);

             setTitle("제곱 계산하기");

             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 

             ButtonListener listener = new ButtonListener();   // 리스너 객체 생성

            

             JPanel panel = new JPanel();

             panel.add(new JLabel("숫자 입력: "));    // 레이블 생성

             text = new JTextField(15);       // 컬럼수가 15 텍스트 필드 생성

             text.addActionListener(listener);   // 텍스트 필드에 리스너 연결

             panel.add(text);

 

             panel.add(new JLabel("제곱한 : "));

             result = new JTextField(15); // 결과를 나타낼 텍스트 필드 

             result.setEditable(false);       // 편집 불가 설정

             panel.add(result);

           button = new JButton("OK");

           button.addActionListener(listener);

           panel.add(button);

           add(panel);

           setVisible(true);

     }

     // 텍스트 필드와 버튼의 액션 이벤트 처리

     private class ButtonListener implements ActionListener {

           public void actionPerformed(ActionEvent e) {

                  if (e.getSource() == button || e.getSource() == text) {

                         String name = text.getText();

                         int value = Integer.parseInt(name);

                         boolean isPrimeNumber = false;

                        

                         // 계산

                         int count = 0;

                         for( int i = 1 ; i <= value ; i++)

                         {

                         //계산

                         if( value % i == 0)

                         {

                             count++;

                         }

                         

                         }

                        

                         if(count == 2)

                         {

                         isPrimeNumber = true;

                         }

                         

                         if(isPrimeNumber)

                         {

                         result.setText("소수입니다.");

                         }

                         else

                         {

                         result.setText("소수가 아닙니다.");

                         }

                                                 

                         text.requestFocus();

                  }

           }

     }

}

public class TextFieldTest extends JFrame {

     public static void main(String[] args) {

           new MyFrame();

     }

}

 

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA GUI 계산기 소스코드  (0) 2013.12.22
JAVA 소수를 구하는 프로그램 GUI #2  (0) 2013.12.21
JAVA 버블 정렬  (0) 2013.11.30
JAVA JTable 실습 예제  (0) 2013.08.24
JAVA 채팅 프로그램 소스  (0) 2013.08.23

달력 만들기 실습 결과

실습과제 모음 2013. 12. 15. 11:22 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
#include 
#include 
using namespace std;

int leapYear(int year);
// 리턴값 1 : 윤년
// 리턴값 0 : 평년

int dayByYear(int year);
//  0    1    2   3    4    5   6
// "일","월","화","수","목","금","토"

int dayByMonthYear(int year, int month);
//  0    1    2   3    4    5   6
// "일","월","화","수","목","금","토"

int totalDayCountByMonthYear(int year, int month);

int main()
{
	char* week[7] = {"일","월","화","수","목","금","토"};	
	int year, month;
	printf("연도를 입력하세요 : ");
	scanf("%d", &year);
	printf("월을 입력하세요 : ");
	scanf("%d", &month);
	printf("%s\n", week[dayByMonthYear(year, month)]);
	
	printf("%5s%5s%5s%5s%5s%5s%5s\n", 
		"일","월","화","수","목","금","토");
	for( int i = 0 ; i < dayByMonthYear(year, month) ; i++ )
	{
		printf("     ");
	}
	int wcount = dayByMonthYear(year, month);
	for ( int i = 1 ; i <= totalDayCountByMonthYear(year, month) ; i++ )
	{
		
		printf("%5d", i);
		if( wcount%7 == 6)
		{
			printf("\n");
		}
		wcount++;
	}

	return 0; 
}
int totalDayCountByMonthYear(int year, int month)
{
	switch(month)
	{
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		return 31;
	case 2:
		if( leapYear(year) )
		{
			return 29;
		}
		else
		{
			return 28;
		}
	default:
		return 30;
	}
}
int dayByMonthYear(int year, int month)
{	
	int wcount=0;
	wcount=(365*year + year/4 - year/100 + year/400)%7;
	// 0 ~ 6
	for( int i = 1 ; i < month ; i++ )
	{
		wcount += totalDayCountByMonthYear(year, i);
	}
	// 30 ~ 300
	wcount %= 7;
	return wcount;
}
int dayByYear(int year){
	int wcount=0;
	wcount=(365*year + year/4 - year/100 + year/400)%7;
	return wcount;
}
int leapYear(int year)
{
	if( year % 4 == 0)
	{
		if( year % 100 == 0)
		{
			if( year % 400 == 0 )
			{
				return 1;
				// 윤년
			}
			else
			{
				return 0;
				// 평년
			}
		}
		else
		{
			return 1;
			// 윤년
		}
	}
	else
	{
		return 0;
		// 평년
	}
}




'실습과제 모음' 카테고리의 다른 글

실습과제 모음  (0) 2013.12.31
CPP 함수 실습  (0) 2013.12.22
달력 만들기 실습  (1) 2013.12.15
게시판에 간단한 채팅방 만들기  (0) 2013.11.28
JAVA 실습 2013 11 23  (0) 2013.11.23

달력 만들기 실습

실습과제 모음 2013. 12. 15. 10:36 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

2013

12

1

2 3 4 5 6 7 8

....

1. 프로그램 (윤년 판단)

input 2013

output 평년

input 2012

output 윤년


2. 프로그램 ( x년도 1월 1일은 무슨 요일)

input 2013

output 월요일

input 2012

output 화요일


3. 프로그램 ( x년도 y월은 총 몇 일)

input 2013 12

output 31

input 2012 11

output 30



'실습과제 모음' 카테고리의 다른 글

CPP 함수 실습  (0) 2013.12.22
달력 만들기 실습 결과  (0) 2013.12.15
게시판에 간단한 채팅방 만들기  (0) 2013.11.28
JAVA 실습 2013 11 23  (0) 2013.11.23
C 언어 과제 11/23  (0) 2013.11.23
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
#include
#define MAX 100
int main(void)
{
	FILE* stream;	// 파일 포인터 생성 
	char bufferString[100];
	char tempString[100];
	char day[200][15];
	char time[200][10];
	int data[200][10];
	int dataAverage[10]= {0};
	int i, j, totalCount = 0;

	char *token;
	char* delimeter = ",";
	stream = fopen("data3.txt","a+");
	// 파일 열기
	// 키보드로 입력 받아 buffer에 저장
	fseek(stream,0,SEEK_SET);

	fscanf(stream,"%s", bufferString);
	fscanf(stream,"%s", bufferString);
	fscanf(stream,"%s", bufferString);
	fscanf(stream,"%s", bufferString);
	// 원하는 SEEK 에 도달

	while(!feof(stream))
	{
		fscanf(stream,"%s", tempString);
		// 2013-12-07
		fscanf(stream,"%s", bufferString);
		// 09:02:55,56,82,30,56,80,25,55,80,24,230
		strcat(tempString, ",");
		strcat(tempString, bufferString);
		//printf("%s\n", tempString);

		i = 0;
		j = 0;
		token = strtok(tempString, delimeter);
		while(token != NULL)  
		{
			printf("%s\n", token);
			switch(i)
			{
			case 0:
				strcpy(day[totalCount],token);
				break;
			case 1:
				strcpy(time[totalCount],token);
				break;
			default:
				data[totalCount][j] = atoi(token);
				j++;
				break;
			}
			token = strtok(NULL, delimeter);    //토큰으로 분리할 문자가 없는경우 NULL리턴			
			i++;
		}
		totalCount++;
	}

	printf("Data Count : %d\n", totalCount );
	
		printf("%7s %7s %7s %7s %7s %7s %7s %7s %7s %7s\n"
			, "LT-101","PT-101","TE-101","LT-102","PT-102","TE-102","LT-103","PT-103","TE-103","MFM-101");
		for( j = 0 ; j < 10 ; j++ )
		{
			for( i = 0 ; i < totalCount ; i++ )
			{
				dataAverage[j] += data[i][j];
			}
		}
		for( j = 0 ; j < 10 ; j++ )
		{
			for( i = 0 ; i < totalCount ; i++ )
			{
				if( data[i][j]>(dataAverage[j] / totalCount)*2)
				{
					printf("ERROR!!! %s %s 에 발생한 에러! \n", day[i], time[i]);
					
				}
			}
		}
		printf("%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf %7.2lf %7.2lf %7.2lf %7.2lf %7.2lf"
			, (double)dataAverage[0] / totalCount
			, (double)dataAverage[1] / totalCount
			, (double)dataAverage[2] / totalCount
			, (double)dataAverage[3] / totalCount
			, (double)dataAverage[4] / totalCount
			, (double)dataAverage[5] / totalCount
			, (double)dataAverage[6] / totalCount
			, (double)dataAverage[7] / totalCount
			, (double)dataAverage[8] / totalCount
			, (double)dataAverage[9] / totalCount
			);
		
	// 파일(stream)에 buffer 내용 쓰기
	fclose(stream);
	// 파일(stream) 닫기
	return 0;
}


'Programming > C,CPP,CS' 카테고리의 다른 글

[Windows7] Internet Explorer 아이콘 사라짐 안보임  (1) 2014.01.04
Visual Studio 2010 Express Version  (0) 2013.12.28
C 패턴 분석 프로그램  (0) 2013.12.08
C언어 달력 소스코드  (0) 2013.08.02
아스키코드표  (0) 2013.05.02

C 패턴 분석 프로그램

Programming/C,CPP,CS 2013. 12. 8. 11:07 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <stdio.h>

 

int main()

{

   int i;

   int type  = -1;

   // 0 :

   // 1 : 부팅

   int s1 = 3;

   int s2 = 5;

   int s[2] = {3,5};

 

   char patternString[2][10] = {"",

       ""};

   char resultString[2][30] = {" 안하세",

      "탭이 켜져있나?"};

   char string[20];

   int j;


   gets(string);

 

   for( j = 0 ; j < 2; j++)

   {

       i = match(string,patternString[j]);

       // java : strstr

       if( i != -1)

       {

          type = j;

       }

   }

   if( type != -1 )

   {

       printf("%s\n", resultString[type]);

   }

   return 0;

}

 

int match(char text[], char pattern[]) {

  int c, d, e, text_length, pattern_length, position = -1;

 

  text_length    = strlen(text);

  pattern_length = strlen(pattern);

 

  if (pattern_length > text_length) {

    return -1;

  }

 

  for (c = 0; c <= text_length - pattern_length; c++) {

    position = e = c;

 

    for (d = 0; d < pattern_length; d++) {

      if (pattern[d] == text[e]) {

        e++;

      }

      else {

        break;

      }

    }

    if (d == pattern_length) {

      return position;

    }

  }

 

  return -1;

}

 

'Programming > C,CPP,CS' 카테고리의 다른 글

Visual Studio 2010 Express Version  (0) 2013.12.28
측정값 오류 찾기 + 파일 입출력  (0) 2013.12.08
C언어 달력 소스코드  (0) 2013.08.02
아스키코드표  (0) 2013.05.02
프로그래밍용으로 좋은 폰트  (0) 2013.03.23