배열 비교에대해

bosungs2y의 이미지

현재 프로그램에 적용 시킬라고 일단 간단하게 따른프로젝트에 소스를 제작중에 있는데
간단한거 같은데 제가생각한대로 잘안되네요...

// a배열에 값을 b배열 값과 일치하면 일치 라는 메세지를 띄울려고 하는데... 이상하게 되는군요...
만약 b배열의 값이 길어지면 제 소스는 길어질뿐더러... 정말 간단한거 같았는데 ㅠㅠ 제소스 문제점좀 분석좀 부탁드립니다...ㅠㅠ

//이정도 길이를 비교할 예정입니다.
a[]="123%34%23%27%27abcd"
b[]="%23%27%27"

////밑에는 제가 짠 소스입니다..(Test용) //

#include

main()
{
char a[5]="xx1%";
char b[3]="1%";
int i,j = 0;

int aa= 0;
int bb= 0;
aa = sizeof(a);
bb = sizeof(b);
for(i=0; i {
for(j=0; j {
if(a[i]==b[j])
{
if(a[i+1]==b[j+1])
{
printf("일치\n");

}
}
}
}
return 0;
}

bosungs2y의 이미지

#include <stdio.h>
 
main()
{
	char a[5]="xx1%";
	char b[3]="1%";
	int i,j = 0;
 
	int aa= 0;
	int bb= 0;
	aa = sizeof(a);
	bb = sizeof(b);
	for(i=0; i< aa; i++) 
	{
		for(j=0; j< bb; j++)
		{
			if(a[i]==b[j])
			{
				if(a[i+1]==b[j+1])
				{
					printf("일치\n");
 
				}
			}
		}
	}
	return 0;
}
originerd의 이미지

굳이 직접 코드를 작성하셔야 하는지요?

http://ideone.com/Xc2cPr 한 번 참고해보세요.

"Time you enjoy wasting, was not wasted" - John Lennon

jmonaco88의 이미지

저도 여러가지 my붙여서 mygrep mystrcmp 해봤는데요.. 고려할 점이나 고려사항이 정말 많더라구요..

strcmp 함수를 사용해보심이 어떤지요;

strcmp(a, b) 하면 끝날일이네요

둘이 같다면 == 0 일것이고

왼쪽이 크거나 작으면 값은 음수 또는 양수로 반환이 됩니다~

if ( strcmp(a, b) == 0 ) {
   printf("일치합니다\n");
}

;;이정도..?

익명 사용자의 이미지

두 if문 직전에서 a[i], b[j], a[i+1], b[j+1]을 printf로 출력해보세요.

Anti-Lock의 이미지

작성하신 코드 의도를 보자면...
strstr 함수가 원하시는 것일겁니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.