설명 : 어떤 문자를 입력했는지 알려주는 프로그램입니다.




#include <stdio.h>


#include <string.h>


 


int main(void)



char str[256];


int i=0,j=0; 


int cntUpper, cntLower, cntNumber, cntSymbol,blank;




char charArr[53] = {0,};



int numArr[53] = {0,};


 


cntUpper = cntLower = cntNumber = cntSymbol =blank= 0; 


printf("문자를 입력하세요. :\n ");


gets(str);


for (; str[i] !='\0'; i++)



if (str[i] >= 'A' && str[i] <= 'Z') 


cntUpper++; 


else if (str[i] >= 'a' && str[i] <= 'z') 


cntLower++; 


else if (str[i] >= '0' && str[i] <= '9') 


cntNumber++;


else if(str[i]==' ')


blank++;


else 


cntSymbol++;


 



for(j=0 ; charArr[j] != 0 ; j++)


{



if(charArr[j] == str[i])


{


numArr[j]++;


break;


}


}


if(charArr[j] == 0)


{


charArr[j] = str[i];


numArr[j]++;


}


 



printf("전체 문자열 길이 : %d\n", i); 


printf("영문자 대문자 갯수 : %d\n", cntUpper); 


printf("영문자 소문자 갯수 : %d\n", cntLower); 


printf("숫자 문자 갯수 : %d\n", cntNumber); 


printf("특수 문자 갯수 : %d\n", cntSymbol);


printf("공백 갯수 : %d\n", blank);


printf("동일 문자의 갯수 "); 


for(i=0 ; charArr[i] != 0 ; i++)


{



if(charArr[i] == ' ')


{


printf("blank:%d  ", numArr[i]);


}


else


{


printf("%c:%d  ", charArr[i], numArr[i]);


}


}


printf("\n");


return 0;



방명록이나 댓글로 질문 남겨주세요.


'IT > C' 카테고리의 다른 글

C언어 내림차순 정렬 프로그램  (0) 2017.07.17
C언어 단어 순서 비교  (0) 2017.07.17

arr 배열에 들어있는 값을 내림차순으로 정렬해준다.



#include <stdio.h>


int main(void)

 {

     double arr[10] = {12.34, 34.56, 43.45, 55.67, 3.89, 213.2, 345.67, 88.23, 465.1, 2.12};

     int i, j=0, index;

     double b;


      for(i = 0 ; i < 9 ; i++)

      {

         index=i;

         for(j=i+1; j<10; j++)

         {

             if (arr[index] > arr[j])

         index=j;

   }

   b=arr[i];

   arr[i]=arr[index];

   arr[index]=b;

    }


  

  

     printf("삽입 정렬 결과\n");

     for(i = 0 ; i < 10 ; i++)

     {

         printf("%.2f ", arr[i]);

     }

     printf("\n");

   

     return 0;

 }

}


질문 사항은 댓글로 남겨주세요.

'IT > C' 카테고리의 다른 글

C언어 문자 종류별 개수, 각 문자 개수 구하기  (0) 2017.07.17
C언어 단어 순서 비교  (0) 2017.07.17

프로그램 설명 : 두 개의 배열을 만들고 각 배열에 단어를 담는다.

소문자가 담기는 경우도 있기 때문에 모든 단어를 대문자로 변경한다.

그리고 각 문자의 앞 뒤 여부를 계산해서 앞에 위치하는 단어를 찾아낸다.

만약 각 단어가 같은 경우 다음 글자를 검사한다.

예) (ALONE, APPLE) 첫번 째 글자인 A가 같으므로 두 번째 글자인 L, P를 비교한다.

혹은 두 단어가 완전히 일치하는 경우도 찾아낸다. 


#include <stdio.h>


int main(void)

 {

    char arr[100] = {0};

    char arr1[100] = {0};

    int i=0, sum = 0;

    char *p = arr;

    char *p1=arr1;


   scanf("%s",p);

   scanf("%s",p1);


   for(i=0;p[i]&&p1[i]<'\0';i++)//대문자로 받을 시 모두 소문자로 바꿔줌

   {

    if('A'>p[i]&&'z'<p1[i])

     p[i]=p1[i]-'a'+'A';

       if('A'>p1[i]&&'z'<p1[i])

     p1[i]=p1[i]-'a'+'A';

    }


   i=0;


   if (*(p+i) == *(p1+i) )

       i++; //글자가 같으면 다음 글자 비교


   if( *(p+i) > *(p1+i) ) {

       printf("%s가 %s보다 앞에 있습니다.\n", p1, p);

    } else if((*(p+i))<(*(p1+i))) {

       printf("%s가 %s보다 앞에 있습니다.\n", p, p1);

    } else {

       printf("두 문자열이 같습니다.\n");

    }

    return 0;

 }


방명록이나 댓글로 질문 남겨주세요.

'IT > C' 카테고리의 다른 글

C언어 문자 종류별 개수, 각 문자 개수 구하기  (0) 2017.07.17
C언어 내림차순 정렬 프로그램  (0) 2017.07.17

쉽다.

아래의 코드를 복사 붙여넣기만 해도 된다.


준비물 :

res 폴더 -> raw 폴더 생성 -> raw 폴더에 동영상 삽입



VedioView로 화면을 꽉 채운다.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<VideoView
android:id="@+id/video_view"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/

</RelativeLayout> 



아래 주석을 참고

MainActivity

package kr.waem.www.videotest;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.VideoView;

public class MainActivity extends Activity {
private String TAG = "VideoActivity";
private VideoView videoView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mVideoview = (VideoView) findViewById(R.id.video_view);
//play video
mVideoview.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.wild_life));

mVideoview.start();
//loop
mVideoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true); // 동영상 무한 반복. 반복을 원치 않을 경우 false
}
});
}

}


생각보다 간단하게 만들었다.

위 코드만 복사해도 충분히 만들 것 같다.

Adapter를 아래 처럼 바꾼다.

가장 중요한 것은 View.setFocusable(false);와

ImageButton -> ImageView, Button -> TextView라는 것이다.

버튼을 뷰로 바꿔도 클릭이 정상적으로 먹힌다.

클릭만 먹히면 되니 이런 식으로 하는 것이 좋다. // 버튼으로 할 경우 OnClickListener()이 안 먹힘.


예시 코드 :


// getView

@Override


public View getView(int position, View convertView, ViewGroup parent) {

View v = convertView;

if (v == null) {
holder = new ViewHolder();
v = mInflater.inflate(R.layout.list_contacts, null);
holder.mainName = (TextView) v.findViewById(R.id.tv_main_name);
holder.mainFavoritesSwitch = (ImageView) v.findViewById(R.id.iv_main_favorits_switch);
holder.mainCall = (ImageView) v.findViewById(R.id.iv_main_call);
holder.mainMan = (ImageView) v.findViewById(R.id.iv_main_man);
holder.mainName.setFocusable(false);
holder.mainFavoritesSwitch.setFocusable(false);
holder.mainCall.setFocusable(false);
holder.mainMan.setFocusable(false);

v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}

//InfoClass를 생성하여 각 뷰의 포지션에 맞는 데이터를 가져옴
InfoClass info = InfoArr.get(position);

//리스트뷰의 아이템에 맞는 String값을 입력
holder.mainName.setText(info.name);

return v;
}



//ViewHolder

private class ViewHolder {

TextView mainName;

ImageView mainFavoritesSwitch;

ImageView mainCall;

ImageView mainMan;

} 


안드로이드 자체 버그로 보인다.

다른 해결책이 있을 수도 있다.

ImageButton이든 ImageView든 클릭만 먹히면 되니 이렇게 해도 무방하다고 본다.

+ Recent posts